Fix: Forzar mimetype ogg para notas de voz PTT
All checks were successful
build-and-deploy / build-and-deploy (push) Successful in 1m11s
All checks were successful
build-and-deploy / build-and-deploy (push) Successful in 1m11s
- 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
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user