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
|
// Get preferred MIME type for recording
|
||||||
|
// Prefer ogg/opus as it's required by WhatsApp for voice notes
|
||||||
const getMimeType = (): string => {
|
const getMimeType = (): string => {
|
||||||
const types = [
|
const types = [
|
||||||
|
'audio/ogg;codecs=opus', // Preferred for WhatsApp PTT
|
||||||
|
'audio/ogg',
|
||||||
'audio/webm;codecs=opus',
|
'audio/webm;codecs=opus',
|
||||||
'audio/webm',
|
'audio/webm',
|
||||||
'audio/ogg;codecs=opus',
|
|
||||||
'audio/ogg',
|
|
||||||
'audio/mp4',
|
'audio/mp4',
|
||||||
'audio/mpeg'
|
'audio/mpeg'
|
||||||
]
|
]
|
||||||
|
|
||||||
for (const type of types) {
|
for (const type of types) {
|
||||||
if (MediaRecorder.isTypeSupported(type)) {
|
if (MediaRecorder.isTypeSupported(type)) {
|
||||||
|
console.log('[AudioRecorder] Using MIME type:', type)
|
||||||
return type
|
return type
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.warn('[AudioRecorder] No preferred type supported, using webm fallback')
|
||||||
return 'audio/webm' // fallback
|
return 'audio/webm' // fallback
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -274,10 +274,19 @@ async function handleMediaMessage(
|
|||||||
mimetype: file.type
|
mimetype: file.type
|
||||||
} as AnyMediaMessageContent
|
} as AnyMediaMessageContent
|
||||||
} else if (mediaType === 'audio') {
|
} 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 = {
|
content = {
|
||||||
audio: file.data,
|
audio: file.data,
|
||||||
ptt: isPtt,
|
ptt: isPtt,
|
||||||
mimetype: file.type
|
mimetype: audioMimetype
|
||||||
} as AnyMediaMessageContent
|
} as AnyMediaMessageContent
|
||||||
} else {
|
} else {
|
||||||
// Document
|
// Document
|
||||||
|
|||||||
Reference in New Issue
Block a user