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 <noreply@anthropic.com>
This commit is contained in:
parent
a53eceb83a
commit
fa9888f83e
10
app/main.py
10
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",
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue