fix(tts): transcode xAI TTS output to Opus when .ogg requested (#57213) - #57518
fix(tts): transcode xAI TTS output to Opus when .ogg requested (#57213)#57518AlexFucuson9 wants to merge 1 commit into
Conversation
…esearch#57213) xAI's /v1/tts API only supports mp3 and wav codecs. When the caller requests an .ogg output path (e.g. Telegram auto voice replies via _send_voice_reply), MP3 bytes were silently written into the .ogg-named file, producing broken/unplayable voice bubbles. Fix: detect .ogg output paths in _generate_xai_tts, write the API response to a temp .mp3 file, then transcode to Opus/OGG using the existing _convert_to_opus helper (ffmpeg). Falls back to the mp3 file if ffmpeg is unavailable so the caller still gets audio. This follows the same pattern already used by the dispatcher-level opus conversion for other providers (edge, openai, etc.). Closes NousResearch#57213
|
teknium1
left a comment
There was a problem hiding this comment.
Thanks for targeting a real xAI/Telegram incompatibility: current main still writes xAI's MP3 response into a requested .ogg path at tools/tts_tool.py:1370-1413, while Telegram auto replies request .ogg at gateway/run.py:13300-13310.
Problems
tools/tts_tool.py:1300returns the OGG beside the temporary MP3._convert_to_opus()derives that name from its input (tools/tts_tool.py:920), so it is not the requested output path.- The xAI dispatch at
tools/tts_tool.py:2443-2445ignores that return value, then validates the original.oggpath attools/tts_tool.py:2528-2533. The proposed successful-conversion path therefore reports no output. - This PR changes only
tools/tts_tool.py; please add a regression test for this.oggpath.
Suggested changes
- Move/replace the converted OGG onto
output_pathbefore returning, or propagate the actual returned path through the dispatcher and correctly handle the MP3 fallback. - Add a test that verifies the requested
.oggpath is the converted output, including ffmpeg-unavailable behavior.
This is an automated hermes-sweeper review.
| os.unlink(_mp3_tmp) | ||
| except OSError: | ||
| pass | ||
| return opus_path |
There was a problem hiding this comment.
_convert_to_opus() derives an OGG beside this temporary MP3, but text_to_speech_tool() ignores the xAI generator's return value (tools/tts_tool.py:2443-2445) and still validates the original requested .ogg path. Move the converted file to output_path before returning, or propagate the returned path through the dispatcher.
|
Resolved at the class level by PR #73072. Rather than a per-provider transcode, |
Problem
xAI /v1/tts API only supports mp3/wav codecs. When caller requests .ogg output (Telegram auto voice replies), MP3 bytes silently written into .ogg file -> broken voice bubbles.
This is xAI instance of known bug class (#57048, #54589). Existing fixes (#55278, #57069, #56873) target other providers but none covers xAI.
Root Cause
tools/tts_tool.py::_generate_xai_tts:
codec = wav if .wav else mp3 -- no .ogg handling. xAI API has no native Opus codec.
Fix
When output_path ends with .ogg:
Same pattern as dispatcher-level opus conversion for other providers.
Closes #57213