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