Repository navigation
fix(tts): avoid mislabeled local and ElevenLabs audio - #125628
Conversation
Detect local CLI audio containers before conversion and derive ElevenLabs delivery metadata from the effective output format. This prevents MP3 or PCM bytes from being persisted or delivered under incompatible file and voice metadata.
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 18, 2026, 6:08 AM ET / 10:08 UTC. ClawSweeper reviewWhat this changesThis PR detects local CLI audio containers before conversion and makes ElevenLabs buffered and streaming metadata reflect the requested output format. Regression provenancePossible regression — probable (reviewed change; known regression link). No predecessor PR is attributed. Merge readinessNo blocking correctness finding remains on the reviewed head: all Ogg is now converted before local-CLI voice compatibility is asserted, and ElevenLabs derives metadata from the effective output format. Keep this protected maintainer PR open until exact-head CI completes. Priority: P1 Review scores
Verification
Live VerificationCommand: Result: PASS (completed) Assertions:
How this fits togetherTTS provider plugins return audio bytes plus format and voice-note compatibility facts to the shared TTS runtime. That runtime persists the result and uses those facts to select ordinary audio-file or native voice-note delivery. flowchart LR
A[TTS request] --> B[Local CLI or ElevenLabs plugin]
B --> C[Detect source or effective output format]
C --> D[Convert local source audio when needed]
D --> E[Return truthful audio metadata]
E --> F[Shared TTS runtime]
F --> G[Audio-file or voice-note delivery]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +66, Tests +376. Total +442 across 6 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Mantis proof suggestionA Telegram Desktop before/after proof would show the user-visible result of corrected voice-note eligibility beyond the provider-level live evidence. A maintainer can ask Mantis to capture proof by posting this exact PR comment: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Retain the source-first local normalization and shared effective-format plan, then land after exact-head checks verify the intended compatibility correction. Do we have a high-confidence way to reproduce the issue? Yes—current-main source directly shows extension-only local format selection and target-only ElevenLabs voice metadata; the PR also records real local ffmpeg and authenticated provider after-fix runs, though this read-only review did not execute them. Is this the best way to solve the issue? Yes—the all-Ogg conversion path removes fragile codec inference, while one ElevenLabs output plan keeps buffered and streaming metadata aligned with the API request. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against f72782d87b0c. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (4 earlier review cycles)
|
Treat Ogg as a source container unless its first packet is OpusHead, so Vorbis and M4A inputs are transcoded to the requested target instead of being mislabeled as native voice audio.
|
@clawsweeper re-review Addressed the P1 container-versus-codec finding on
|
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
Require valid MPEG version, layer, bitrate, and sample-rate fields before treating sync bytes as MP3, preventing reserved headers from bypassing conversion under MP3 metadata.
|
@clawsweeper re-review Addressed the exact-head MP3 header finding on
|
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
Require structurally valid ID3v2 metadata followed by a strict MPEG frame, and stop trusting recognizable file extensions when their bytes do not match. Unknown or malformed output now fails closed instead of bypassing conversion.
|
@clawsweeper re-review Addressed the exact-head ID3 finding on
|
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
Treat bitrate index zero as valid free-format MPEG audio and lock the ID3v2.4 footer offset contract with focused regression coverage.
|
@clawsweeper re-review Addressed the widened P2 review on
|
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
Treat Ogg only as a source container and always transcode it to the requested target, so malformed or ambiguous Ogg bytes can never bypass conversion as native voice audio.
|
@clawsweeper re-review Addressed the malformed/native-Ogg P1 on
|
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
Land-ready proof —
|
|
Merged via squash.
|
* fix(tts): report actual audio output formats Detect local CLI audio containers before conversion and derive ElevenLabs delivery metadata from the effective output format. This prevents MP3 or PCM bytes from being persisted or delivered under incompatible file and voice metadata. * fix(tts-local-cli): distinguish Ogg Opus audio Treat Ogg as a source container unless its first packet is OpusHead, so Vorbis and M4A inputs are transcoded to the requested target instead of being mislabeled as native voice audio. * fix(tts-local-cli): validate MP3 frame headers Require valid MPEG version, layer, bitrate, and sample-rate fields before treating sync bytes as MP3, preventing reserved headers from bypassing conversion under MP3 metadata. * fix(tts-local-cli): validate tagged MP3 output Require structurally valid ID3v2 metadata followed by a strict MPEG frame, and stop trusting recognizable file extensions when their bytes do not match. Unknown or malformed output now fails closed instead of bypassing conversion. * fix(tts-local-cli): accept free-format MPEG audio Treat bitrate index zero as valid free-format MPEG audio and lock the ID3v2.4 footer offset contract with focused regression coverage. * fix(tts-local-cli): normalize all Ogg output Treat Ogg only as a source container and always transcode it to the requested target, so malformed or ambiguous Ogg bytes can never bypass conversion as native voice audio.
What Problem This Solves
Fixes two cases where successful TTS synthesis could return audio bytes under false format metadata:
outputFormatoverride could reach the API while the provider still reported the target's default.opus/.mp3extension and voice compatibility.The latter could approve PCM or telephony bytes for voice-note delivery even though the resulting file was not voice-compatible.
Why This Change Was Made
The local CLI provider now distinguishes requested target formats from detected source formats. It identifies WAV directly, accepts untagged MP3 only with a valid MPEG frame header, and accepts ID3v2-tagged MP3 only after validating the tag version, flags, sync-safe length, optional footer, bounds, and the MPEG frame at the computed audio offset. It treats every
OggSresult as a source container and routes it through the existing ffmpeg conversion path, so neither malformed Ogg nor already-Opus Ogg can bypass normalization as native voice audio. M4A is likewise retained only as a source format that must be converted to the configured target. Recognizable file bytes take precedence over a misleading filename, while extension fallback remains for supported containers outside the byte detector.ElevenLabs now resolves one canonical output plan from the effective API format. Buffered and streaming synthesis share that plan, mapping the documented MP3, Opus, PCM, μ-law, A-law, and WAV families to truthful extensions and marking only Opus as voice-compatible.
Production LOC: +93/-27 (net +66) | Tests: +388/-12
The production growth is the source-format boundary needed to distinguish target formats from Ogg/M4A inputs and to validate complete MPEG-frame and ID3v2 evidence before MP3 conversion can be skipped. Ogg never skips conversion.
User Impact
Operators can rely on TTS output metadata matching the audio that was actually produced. Misconfigured local CLIs are converted instead of silently shipping mislabeled files; Ogg Vorbis cannot masquerade as native Opus; and ElevenLabs overrides no longer cause raw PCM or telephony audio to be persisted as Opus or delivered as a voice note.
Evidence
FF F1, bareID3prefixes, malformed sync-safe ID3 lengths, and tagged invalid frames were accepted as MP3 and skipped conversion;node scripts/run-vitest.mjs extensions/tts-local-cli/speech-provider.test.ts extensions/tts-local-cli/speech-provider-stream-error.test.tsnode scripts/run-vitest.mjs extensions/elevenlabs/speech-provider.test.tsOPENCLAW_LIVE_TEST=1 pnpm test:live extensions/tts-local-cli/speech-provider.live.test.tsOpusHeadoutput.pcm_24000on a voice-note target:.pcm,voiceCompatible=false, 115,914 bytes;.pcm,voiceCompatible=false, 118,144 bytes.node scripts/check-changed.mjs -- extensions/tts-local-cli/speech-provider.ts extensions/tts-local-cli/speech-provider.test.ts extensions/tts-local-cli/speech-provider-stream-error.test.ts extensions/tts-local-cli/speech-provider.live.test.tsgit diff --checkautoreview --mode uncommitted --max-priority P2after the Ogg always-convert simplification: clean, no accepted/actionable findings.AI-assisted: yes. The implementation was reviewed and validated by the maintainer before publication.