Add webm response format (opus in webm container)

Firefox MediaSource API supports audio/webm;codecs=opus but not
audio/ogg. Adding webm format lets Firefox clients use true
streaming playback via MediaSource instead of full buffering.
This commit is contained in:
russell@unturf.com 2026-01-27 09:28:38 -05:00
parent 8f7f1318a1
commit 16b281bab4

View file

@ -602,6 +602,8 @@ def build_ffmpeg_args(response_format, input_format, sample_rate):
ffmpeg_args.extend(["-f", "flac", "-c:a", "flac"])
elif response_format == "wav":
ffmpeg_args.extend(["-f", "wav", "-c:a", "pcm_s16le"])
elif response_format == "webm":
ffmpeg_args.extend(["-f", "webm", "-c:a", "libopus"])
elif response_format == "pcm": # even though pcm is technically 'raw', we still use ffmpeg to adjust the speed
ffmpeg_args.extend(["-f", "s16le", "-c:a", "pcm_s16le"])
@ -749,6 +751,8 @@ async def generate_speech(request: GenerateSpeechRequest):
media_type = "audio/x-flac"
elif response_format == "wav":
media_type = "audio/wav"
elif response_format == "webm":
media_type = "audio/webm;codecs=opus"
elif response_format == "pcm":
if model == 'tts-1': # piper
media_type = "audio/pcm;rate=22050"