Fix audio device: dynamische Kartensuche statt hardcoded plughw:2,0
Nach Neustart wechselt die ALSA-Kartennummer (war 2, ist jetzt 1). find_audio_device() sucht per /proc/asound/cards nach dem USB-Gerät. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
e4b8cc55f7
commit
28eb07bcab
18
app/main.py
18
app/main.py
|
|
@ -111,17 +111,31 @@ def stream():
|
||||||
# Minimale Latenz: kein HTTP-Buffering, kein Codec-Delay
|
# Minimale Latenz: kein HTTP-Buffering, kein Codec-Delay
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
|
|
||||||
AUDIO_DEVICE = "plughw:2,0"
|
|
||||||
AUDIO_SAMPLERATE = 16000
|
AUDIO_SAMPLERATE = 16000
|
||||||
AUDIO_CHUNK = 512 # ~32ms bei 16kHz
|
AUDIO_CHUNK = 512 # ~32ms bei 16kHz
|
||||||
|
|
||||||
|
|
||||||
|
def find_audio_device() -> str:
|
||||||
|
"""Findet die USB-Soundkarte dynamisch anhand des Namens."""
|
||||||
|
try:
|
||||||
|
with open("/proc/asound/cards") as f:
|
||||||
|
for line in f:
|
||||||
|
# Zeile mit Kartennummer: " 1 [Device ]: USB-Audio ..."
|
||||||
|
m = re.match(r"^\s*(\d+)\s+\[.*\].*USB", line)
|
||||||
|
if m:
|
||||||
|
return f"plughw:{m.group(1)},0"
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
return "plughw:1,0" # Fallback
|
||||||
|
|
||||||
|
|
||||||
@sock.route("/audio-ws")
|
@sock.route("/audio-ws")
|
||||||
def audio_ws(ws):
|
def audio_ws(ws):
|
||||||
|
device = find_audio_device()
|
||||||
process = subprocess.Popen(
|
process = subprocess.Popen(
|
||||||
[
|
[
|
||||||
"arecord",
|
"arecord",
|
||||||
"-D", AUDIO_DEVICE,
|
"-D", device,
|
||||||
"-f", "S16_LE",
|
"-f", "S16_LE",
|
||||||
"-r", str(AUDIO_SAMPLERATE),
|
"-r", str(AUDIO_SAMPLERATE),
|
||||||
"-c", "1",
|
"-c", "1",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue