fix(tts): honor wav/flac output in OpenAI TTS provider instead of forcing mp3 - #37337
Closed
MarvinFS wants to merge 1 commit into
Closed
fix(tts): honor wav/flac output in OpenAI TTS provider instead of forcing mp3#37337MarvinFS wants to merge 1 commit into
MarvinFS wants to merge 1 commit into
Conversation
…cing mp3
_generate_openai_tts derived the OpenAI response_format solely from a
.ogg check, mapping every other extension - including .wav and .flac -
to mp3. This ignored the configured output_format, which Hermes already
validates against COMMAND_TTS_OUTPUT_FORMATS = {mp3, wav, ogg, flac} and
uses to set the output file extension.
Impact:
- Configured wav/flac output was re-encoded to mp3 (or written as mp3
bytes under a .wav name) even when the backend produced the requested
format natively.
- On OpenAI-compatible backends without server-side mp3 encoding - e.g.
devnen/Chatterbox-TTS-Server, which returns native 24 kHz WAV - the
forced mp3 request failed with "500: Failed to encode audio", breaking
TTS entirely when wav would have worked.
Mirror the sibling Mistral provider and map .wav -> wav and .flac -> flac.
Both are documented OpenAI audio.speech response_format values, so this
stays within the API contract and adds no new config surface.
This was referenced Jun 22, 2026
Closed
13 tasks
teknium1
reviewed
Jul 13, 2026
teknium1
left a comment
Contributor
There was a problem hiding this comment.
Thanks for isolating a real OpenAI TTS format-selection bug: current main still maps every non-.ogg output path to mp3 in tools/tts_tool.py:1050-1054, while the sibling Mistral implementation maps WAV and FLAC explicitly at tools/tts_tool.py:1450-1457.
Problems
- The added
endswith()branches remain case-sensitive. Because caller-provided paths are preserved attools/tts_tool.py:2204,speech.WAVandspeech.FLACwould still request MP3. - The PR adds no regression test. Existing OpenAI tests in
tests/tools/test_tts_speed.py:71-114andtests/tools/test_managed_media_gateways.py:225-302use.mp3only. output_formatis documented for command providers (website/docs/user-guide/features/tts.md:240-315); this built-in OpenAI path is controlled byoutput_path.
Suggested changes
- Normalize
Path(output_path).suffix.lower()once before mapping the response format. - Add mocked request-construction tests for
.ogg,.wav,.flac, and.mp3. - Adjust the PR description to describe output-path extension handling.
Automated hermes-sweeper review.
| # where forcing mp3 yields a hard "500: Failed to encode audio". | ||
| if output_path.endswith(".ogg"): | ||
| response_format = "opus" | ||
| elif output_path.endswith(".wav"): |
Contributor
There was a problem hiding this comment.
Please normalize the suffix once (for example, Path(output_path).suffix.lower()) before this mapping. text_to_speech_tool() preserves a caller-provided path, so .WAV and .FLAC currently still fall through to mp3.
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
tools/tts_tool.py::_generate_openai_ttsderives the OpenAIresponse_formatsolely from a.oggcheck, mapping every other extension — including.wavand.flac— tomp3:This ignores the user's configured
output_format, which Hermes already validates againstCOMMAND_TTS_OUTPUT_FORMATS = {mp3, wav, ogg, flac}and uses to set the output file's extension (_get_command_tts_output_format).Impact:
wav/flacoutput is re-encoded to mp3 (or written as mp3 bytes under a.wavname) even when the backend produces the requested format natively.devnen/Chatterbox-TTS-Server, which returns native 24 kHz WAV — the forced mp3 request fails with500: Failed to encode audio, breaking TTS entirely whenwavwould have succeeded.The sibling Mistral provider in the same file already maps
.ogg/.wav/.flac/elsecorrectly; the OpenAI provider is simply inconsistent with it.Fix
Mirror the Mistral provider and map
.wav -> wav/.flac -> flac. Both are documented values for OpenAI'saudio.speechresponse_format(mp3, opus, aac, flac, wav, pcm), so this stays within the API contract and adds no new config surface — the resolvedoutput_formatalready controls the extension.Testing
output_format: wavagainst an OpenAI-compatible backend returning native WAV (Chatterbox-TTS-Server): now succeeds with a valid WAV instead of500: Failed to encode audio..ogg(opus) and default.mp3paths unchanged.