squad-manager/werkzeuge/mictest.py
danny f986c3ad11 Squad Voice Activation 3.2 - Ausgangsstand
Windows-Werkzeug, das die Sprechtaste in Squad haelt, solange man redet.

- Hauptprogramm mit tkinter-Oberflaeche, Pegelanzeige und Diagnose
- Auto-Updater gegen https://sva.tyrveil.com/version.json mit SHA-256-Pruefung
- Inno-Setup-Installer und Build-Skript werkzeuge/baue_release.py
- Projektuebergabe mit den bekannten Fallstricken

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-10 17:22:54 +02:00

53 lines
1.8 KiB
Python

"""Testet jedes Eingabegeraet in einem eigenen Prozess mit Zeitlimit."""
import subprocess
import sys
PY = sys.executable
CHILD = r'''
import sys, numpy as np, sounddevice as sd
dev = int(sys.argv[1]); sr = int(sys.argv[2])
frames = int(0.7 * sr)
with sd.InputStream(device=dev, channels=1, samplerate=sr, dtype="float32") as s:
data, overflowed = s.read(frames)
rms = float(np.sqrt(np.mean(data**2))); mx = float(np.max(np.abs(data)))
print(f"{rms:.6f} {mx:.6f}")
'''
def main():
import sounddevice as sd
devs = [(i, d) for i, d in enumerate(sd.query_devices())
if d["max_input_channels"] > 0]
print(f"{'Idx':>4} {'Geraet':44} {'SR':>6} {'Ergebnis'}")
print("-" * 92)
for i, d in devs:
name = d["name"][:42]
sr = 48000
try:
sd.check_input_settings(device=i, channels=1, samplerate=sr,
dtype="float32")
except Exception:
sr = int(d["default_samplerate"])
try:
out = subprocess.run([PY, "-c", CHILD, str(i), str(sr)],
capture_output=True, text=True, timeout=6)
except subprocess.TimeoutExpired:
print(f"{i:>4} {name:44} {sr:>6} HAENGT (kein Datenfluss)")
continue
if out.returncode != 0:
err = (out.stderr or "").strip().splitlines()
msg = err[-1][:44] if err else "unbekannter Fehler"
print(f"{i:>4} {name:44} {sr:>6} FEHLER: {msg}")
continue
try:
rms, mx = (float(x) for x in out.stdout.split())
except Exception:
print(f"{i:>4} {name:44} {sr:>6} unlesbare Ausgabe")
continue
tag = "STILLE (exakt 0)" if mx == 0.0 else f"rms={rms:.5f} max={mx:.5f}"
print(f"{i:>4} {name:44} {sr:>6} {tag}")
if __name__ == "__main__":
main()