Skip to content

fix(channels/whatsapp): send ElevenLabs voice notes as Ogg/Opus and sniff audio mime (#6116)#6118

Merged
houko merged 1 commit into
mainfrom
fix/whatsapp-audio-mime-6116
Jun 15, 2026
Merged

fix(channels/whatsapp): send ElevenLabs voice notes as Ogg/Opus and sniff audio mime (#6116)#6118
houko merged 1 commit into
mainfrom
fix/whatsapp-audio-mime-6116

Conversation

@houko

@houko houko commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Summary

Closes #6116. Recovers the fix from the stale-closed PR #5283 (credit: @f-liva), re-derived cleanly on current main.

ElevenLabs TTS returns MP3 by default, but the WhatsApp gateway hard-coded the outgoing mime as audio/ogg; codecs=opus, so the payload (MP3) did not match the declared container.
Mobile WhatsApp tolerated it, but the mautrix-whatsapp / Beeper bridge rejected the message as Unsupported content type in Web mode — a silent drop, no voice bubble.

Change

  • [tts.elevenlabs].output_format config field (default opus_48000_32). The synth path (tts.rs) sends ?output_format= with a 3-tier resolution (tool-arg override > config > built-in default) and labels TtsResult.format from the real format prefix instead of a hardcoded "mp3".
  • The ElevenLabs media driver default flips mp3_44100_128 to opus_48000_32; the TTS tool (tool_runner/media.rs) injects the configured output_format on the media path when the call omits format.
  • The WhatsApp gateway gains detectAudioMime (magic-byte sniff: OggS / ID3 / MPEG-sync / RIFF / fLaC / ftyp); sendAudio sends the detected mime and auto-downgrades PTT to a plain audio attachment (with a warn) for any non-Opus buffer instead of mislabelling it.
  • librefang.toml.example documents the new block; xtask/baselines/config.sha256 regenerated.

Verification

  • cargo check -p librefang-types -p librefang-runtime -p librefang-runtime-media --lib — clean.
  • cargo clippy -p librefang-types -p librefang-runtime -p librefang-runtime-media --all-targets -- -D warnings — 0 warnings.
  • cargo test -p librefang-runtime --lib tts:: — 14 passed, incl. new test_three_tier_resolution_elevenlabs_format and test_default_elevenlabs_format_label_is_opus.
  • cargo test -p librefang-runtime-media — 83 passed.
  • node --test packages/whatsapp-gateway/index.test.js — the new detectAudioMime suite is 9/9 green. (Two pre-existing failures in unrelated forward_dispatch / onOwnerNotice suites reproduce on clean main and are untouched by this change.)
  • Config baseline matches after regeneration.

Behaviour note

Operators whose custom TTS pipelines relied on the ElevenLabs MP3 default must now pass format: "mp3_44100_128" explicitly (or set [tts.elevenlabs].output_format). This is intentional — Opus is required for WhatsApp PTT.

…niff audio mime

ElevenLabs TTS returns MP3 by default, but the WhatsApp gateway hard-coded the outgoing mime as `audio/ogg; codecs=opus`, so the payload (MP3) did not match the declared container.
Mobile WhatsApp tolerated it, but the mautrix-whatsapp/Beeper bridge rejected the message as "Unsupported content type in Web mode" — a silent drop with no voice bubble.

Request Opus from ElevenLabs and stop mislabelling the buffer:
- New `[tts.elevenlabs].output_format` config field (default `opus_48000_32`); the synth path now sends `?output_format=` with a 3-tier resolution (tool-arg override > config > built-in default) and labels `TtsResult.format` from the real format prefix.
- The ElevenLabs media driver defaults to `opus_48000_32` too; the TTS tool injects the configured `output_format` on the media path when the call omits it.
- The WhatsApp gateway gains a `detectAudioMime` magic-byte sniffer; `sendAudio` sends the detected mime and auto-downgrades PTT to a plain audio attachment (with a warn) for any non-Opus buffer instead of corrupting the message.

Tests: tts 3-tier resolution + opus-label unit tests; 9 `detectAudioMime` gateway cases. Config baseline regenerated for the new example block.

Recovers the fix from the stale-closed PR #5283 by @f-liva.
@houko
houko enabled auto-merge (squash) June 15, 2026 09:29
@github-actions github-actions Bot added area/runtime Agent loop, LLM drivers, WASM sandbox area/sdk JavaScript and Python SDKs size/L 250-999 lines changed labels Jun 15, 2026
@houko
houko merged commit 8405728 into main Jun 15, 2026
32 checks passed
@houko
houko deleted the fix/whatsapp-audio-mime-6116 branch June 15, 2026 09:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/runtime Agent loop, LLM drivers, WASM sandbox area/sdk JavaScript and Python SDKs size/L 250-999 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(channels/whatsapp): ElevenLabs MP3 voice notes sent as Ogg/Opus are dropped by the mautrix-whatsapp/Beeper bridge

1 participant