From a53eceb83a9ea3ed1bb86b51822203fcbe64e6dd Mon Sep 17 00:00:00 2001 From: Julian Vollmer Date: Mon, 18 May 2026 18:15:21 +0200 Subject: [PATCH] Add audio streaming via USB microphone MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Neuer Endpunkt GET /audio: ffmpeg liest von plughw:2,0 (USB-Soundkarte CM108) und streamt Ogg/Opus mit 16kHz Mono 24kbps - live.html: Ton-Button (🔇/🔊) startet/stoppt Audio-Stream on demand - setup.sh: ffmpeg installieren, pi zur audio-Gruppe hinzufügen - pi zur audio-Gruppe hinzugefügt (war nötig für /dev/snd Zugriff) Co-Authored-By: Claude Sonnet 4.6 --- app/main.py | 41 +++++++++++++++++++++++++++++++++++++++++ app/templates/live.html | 21 +++++++++++++++++++++ setup.sh | 4 +++- 3 files changed, 65 insertions(+), 1 deletion(-) diff --git a/app/main.py b/app/main.py index 255e47f..b21091e 100644 --- a/app/main.py +++ b/app/main.py @@ -104,6 +104,47 @@ def stream(): ) +# --------------------------------------------------------------------------- +# Audio-Stream (Ogg/Opus via ffmpeg) +# --------------------------------------------------------------------------- + +AUDIO_DEVICE = "plughw:2,0" +AUDIO_SAMPLERATE = 16000 + + +def generate_audio(): + cmd = [ + "ffmpeg", + "-f", "alsa", + "-i", AUDIO_DEVICE, + "-ar", str(AUDIO_SAMPLERATE), + "-ac", "1", + "-c:a", "libopus", + "-b:a", "24k", + "-f", "ogg", + "-", + ] + process = subprocess.Popen( + cmd, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL + ) + try: + while True: + chunk = process.stdout.read(4096) + if not chunk: + break + yield chunk + finally: + process.kill() + + +@app.route("/audio") +def audio(): + return Response( + generate_audio(), + mimetype="audio/ogg; codecs=opus", + ) + + # --------------------------------------------------------------------------- # WLAN-Verwaltung # --------------------------------------------------------------------------- diff --git a/app/templates/live.html b/app/templates/live.html index afa56d5..8155cd1 100644 --- a/app/templates/live.html +++ b/app/templates/live.html @@ -163,9 +163,12 @@
+ âš™ Einstellungen
+ +