From f09ce37897bd8846dab9d9df323e1d257ce516ae Mon Sep 17 00:00:00 2001 From: josedario87 Date: Thu, 4 Dec 2025 10:24:53 -0600 Subject: [PATCH] Fix: Forzar mimetype ogg para notas de voz PTT - Preferir grabacion en ogg/opus en el navegador - Forzar mimetype a audio/ogg; codecs=opus para PTT en servidor - WhatsApp requiere ogg para notas de voz --- app/composables/useAudioRecorder.ts | 7 +++++-- .../api/messages/[instanceId]/[chatId]/send.post.ts | 11 ++++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/app/composables/useAudioRecorder.ts b/app/composables/useAudioRecorder.ts index 0b2f5e1..8359273 100644 --- a/app/composables/useAudioRecorder.ts +++ b/app/composables/useAudioRecorder.ts @@ -36,22 +36,25 @@ export function useAudioRecorder() { }) // Get preferred MIME type for recording + // Prefer ogg/opus as it's required by WhatsApp for voice notes const getMimeType = (): string => { const types = [ + 'audio/ogg;codecs=opus', // Preferred for WhatsApp PTT + 'audio/ogg', 'audio/webm;codecs=opus', 'audio/webm', - 'audio/ogg;codecs=opus', - 'audio/ogg', 'audio/mp4', 'audio/mpeg' ] for (const type of types) { if (MediaRecorder.isTypeSupported(type)) { + console.log('[AudioRecorder] Using MIME type:', type) return type } } + console.warn('[AudioRecorder] No preferred type supported, using webm fallback') return 'audio/webm' // fallback } diff --git a/server/api/messages/[instanceId]/[chatId]/send.post.ts b/server/api/messages/[instanceId]/[chatId]/send.post.ts index 8d63f72..9e0cf99 100644 --- a/server/api/messages/[instanceId]/[chatId]/send.post.ts +++ b/server/api/messages/[instanceId]/[chatId]/send.post.ts @@ -274,10 +274,19 @@ async function handleMediaMessage( mimetype: file.type } as AnyMediaMessageContent } else if (mediaType === 'audio') { + // For PTT (voice notes), WhatsApp requires audio/ogg; codecs=opus + // If the browser sends webm, we force the mimetype to ogg + // The opus codec is the same, just different container + let audioMimetype = file.type + if (isPtt && file.type.includes('webm')) { + audioMimetype = 'audio/ogg; codecs=opus' + console.log(`[Send] Converting PTT mimetype from ${file.type} to ${audioMimetype}`) + } + content = { audio: file.data, ptt: isPtt, - mimetype: file.type + mimetype: audioMimetype } as AnyMediaMessageContent } else { // Document