| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193 |
- """
- Audio Recorder — Debug Diagnostic Tool
- =======================================
- Run this DIRECTLY with Python (not as EXE) to see exactly what's failing.
- python debug_test.py
- It will print a full report and pause at any error so you can read it.
- """
- import sys
- import os
- import time
- import socket
- import traceback
- import subprocess
- print("=" * 60)
- print(" Audio Recorder — Startup Diagnostic")
- print("=" * 60)
- print(f" Python: {sys.version}")
- print(f" EXE: {sys.executable}")
- print(f" CWD: {os.getcwd()}")
- print(f" Script: {os.path.abspath(__file__)}")
- print("=" * 60)
- print()
- errors = []
- # ── 1. Check required packages ────────────────────────────────────────────────
- print("[1] Checking installed packages...")
- packages = {
- "flask": "flask",
- "sounddevice": "sounddevice",
- "soundfile": "soundfile",
- "numpy": "numpy",
- "PIL": "pillow",
- "pystray": "pystray",
- }
- for mod, pip_name in packages.items():
- try:
- __import__(mod)
- print(f" OK {mod}")
- except ImportError as e:
- print(f" MISSING {mod} → pip install {pip_name}")
- errors.append(f"Missing package: {mod} (install with: pip install {pip_name})")
- print()
- # ── 2. Check port 5000 availability ───────────────────────────────────────────
- print("[2] Checking port 5000...")
- try:
- s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- s.settimeout(1)
- result = s.connect_ex(('127.0.0.1', 5000))
- s.close()
- if result == 0:
- print(" WARNING: Port 5000 is already IN USE!")
- print(" Something else is already listening on port 5000.")
- print(" Either stop that app, or change the port in recorder_config.json")
- errors.append("Port 5000 already in use")
- else:
- print(" OK Port 5000 is free")
- except Exception as e:
- print(f" ERROR checking port: {e}")
- print()
- # ── 3. Try importing audio_recorder_server ────────────────────────────────────
- print("[3] Importing audio_recorder_server...")
- # Add current dir to path (simulates what the launcher does)
- script_dir = os.path.dirname(os.path.abspath(__file__))
- if script_dir not in sys.path:
- sys.path.insert(0, script_dir)
- try:
- # Set sys.argv as the launcher would
- sys.argv = [
- "audio_recorder_server.py",
- "--port", "5000",
- "--outdir", "./recordings",
- "--samplerate", "44100",
- "--channels", "2",
- "--format", "WAV",
- ]
- import audio_recorder_server as srv
- print(" OK audio_recorder_server imported")
- try:
- srv.init_from_args()
- print(f" OK init_from_args() called")
- print(f" PORT = {srv.PORT}")
- print(f" OUTPUT_DIR = {srv.OUTPUT_DIR}")
- print(f" DEVICE = {srv.DEVICE}")
- print(f" SAMPLERATE = {srv.SAMPLE_RATE}")
- except Exception as e:
- tb = traceback.format_exc()
- print(f" ERROR in init_from_args():\n{tb}")
- errors.append(f"init_from_args() failed: {tb}")
- except Exception as e:
- tb = traceback.format_exc()
- print(f" ERROR importing audio_recorder_server:\n{tb}")
- errors.append(f"Import failed: {tb}")
- print()
- # ── 4. Check sounddevice / audio devices ─────────────────────────────────────
- print("[4] Checking audio devices...")
- try:
- import sounddevice as sd
- devices = sd.query_devices()
- inputs = [d for d in devices if d['max_input_channels'] > 0]
- print(f" OK Found {len(inputs)} input device(s):")
- for i, d in enumerate(inputs[:5]):
- idx = list(devices).index(d)
- print(f" [{idx}] {d['name']}")
- if len(inputs) == 0:
- print(" WARNING: No audio input devices found!")
- errors.append("No audio input devices found")
- except Exception as e:
- tb = traceback.format_exc()
- print(f" ERROR querying audio devices:\n{tb}")
- errors.append(f"sounddevice error: {tb}")
- print()
- # ── 5. Try starting Flask briefly ────────────────────────────────────────────
- print("[5] Trying to start Flask server for 5 seconds...")
- flask_error = None
- def run_flask():
- global flask_error
- try:
- import audio_recorder_server as srv
- srv.app.run(host="0.0.0.0", port=5000, debug=False,
- threaded=True, use_reloader=False)
- except Exception as e:
- flask_error = traceback.format_exc()
- import threading
- t = threading.Thread(target=run_flask, daemon=True)
- t.start()
- time.sleep(3)
- if flask_error:
- print(f" ERROR starting Flask:\n{flask_error}")
- errors.append(f"Flask startup error: {flask_error}")
- else:
- # Try hitting the API
- try:
- import urllib.request
- with urllib.request.urlopen("http://localhost:5000/api/status", timeout=2) as r:
- data = r.read()
- print(f" OK Flask responded: {data.decode()[:80]}")
- except Exception as e:
- print(f" WARNING: Flask started but /api/status failed: {e}")
- if not flask_error:
- errors.append(f"Flask not responding: {e}")
- print()
- # ── 6. Check firewall hint ────────────────────────────────────────────────────
- print("[6] Checking local IP...")
- try:
- s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
- s.connect(("8.8.8.8", 80))
- ip = s.getsockname()[0]
- s.close()
- print(f" OK Local IP: {ip}")
- print(f" ESP32 should connect to: http://{ip}:5000")
- except Exception as e:
- print(f" ERROR: {e}")
- print()
- # ── Summary ───────────────────────────────────────────────────────────────────
- print("=" * 60)
- if errors:
- print(f" FOUND {len(errors)} PROBLEM(S):")
- for i, e in enumerate(errors, 1):
- print(f"\n [{i}] {e[:200]}")
- else:
- print(" ALL CHECKS PASSED!")
- print(" The server should work. Try running AudioRecorder.exe again.")
- print()
- print(" If the EXE still fails, run BUILD.bat again to rebuild it")
- print(" with the latest files.")
- print()
- print("=" * 60)
- input("\nPress Enter to exit...")
|