From fa9888f83ee2fcdd12167de79db9bac83e3cf3f6 Mon Sep 17 00:00:00 2001 From: Julian Vollmer Date: Mon, 18 May 2026 18:19:34 +0200 Subject: [PATCH] Reduce audio stream latency - fflags nobuffer + flags low_delay: ffmpeg Input-Buffer deaktiviert - frame_duration 20ms + page_duration 20ms: kleinste Ogg-Pages - flush_packets 1: sofortiges Schreiben nach jedem Frame - HTTP Header no-cache + X-Accel-Buffering no: kein Proxy/Flask-Buffering Co-Authored-By: Claude Sonnet 4.6 --- app/main.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/main.py b/app/main.py index b21091e..b92055c 100644 --- a/app/main.py +++ b/app/main.py @@ -115,12 +115,18 @@ AUDIO_SAMPLERATE = 16000 def generate_audio(): cmd = [ "ffmpeg", + "-fflags", "nobuffer", + "-flags", "low_delay", "-f", "alsa", + "-thread_queue_size", "128", "-i", AUDIO_DEVICE, "-ar", str(AUDIO_SAMPLERATE), "-ac", "1", "-c:a", "libopus", "-b:a", "24k", + "-frame_duration", "20", + "-page_duration", "20000", + "-flush_packets", "1", "-f", "ogg", "-", ] @@ -142,6 +148,10 @@ def audio(): return Response( generate_audio(), mimetype="audio/ogg; codecs=opus", + headers={ + "Cache-Control": "no-cache, no-store", + "X-Accel-Buffering": "no", + }, )