From 924d9e34ef46e6d4f958a754e29f9a23b5940b12 Mon Sep 17 00:00:00 2001 From: Shawn <118158941+kevinWangSheng@users.noreply.github.com> Date: Mon, 2 Mar 2026 17:00:04 -0800 Subject: [PATCH] fix(discord): resample audio to 48kHz for voice messages (#32298) Fixes #32293: Discord voice message plays at ~0.5x speed with 24kHz TTS source When TTS providers (like mlx-audio Qwen3-TTS) output audioHz, Discord voice at 24k messages play at half speed because Discord expects 48kHz. This fix adds explicit sample rate conversion to 48kHz in the ensureOggOpus function, ensuring voice messages always play at correct speed regardless of the input audio's sample rate. Co-authored-by: Kevin Shenghui --- src/discord/voice-message.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/discord/voice-message.ts b/src/discord/voice-message.ts index f7d76d12ec9..23dffd3833f 100644 --- a/src/discord/voice-message.ts +++ b/src/discord/voice-message.ts @@ -182,6 +182,8 @@ export async function ensureOggOpus(filePath: string): Promise<{ path: string; c } // Convert to OGG/Opus + // Always resample to 48kHz to ensure Discord voice messages play at correct speed + // (Discord expects 48kHz; lower sample rates like 24kHz from some TTS providers cause 0.5x playback) const tempDir = resolvePreferredOpenClawTmpDir(); const outputPath = path.join(tempDir, `voice-${crypto.randomUUID()}.ogg`); @@ -189,6 +191,8 @@ export async function ensureOggOpus(filePath: string): Promise<{ path: string; c "-y", "-i", filePath, + "-ar", + "48000", "-c:a", "libopus", "-b:a",