feat: convert outgoing audio to MP3 inside send_media case to bypass getAudioDuration
This commit is contained in:
@@ -459,10 +459,24 @@ async function handleMessage(ws, raw) {
|
||||
if (!clientReady) {
|
||||
return respond({ type: 'error', message: 'WhatsApp is not ready' });
|
||||
}
|
||||
const { chatId, base64, mimetype, filename, caption } = payload;
|
||||
let { chatId, base64, mimetype, filename, caption } = payload;
|
||||
if (!chatId || !base64 || !mimetype) {
|
||||
return respond({ type: 'error', message: 'chatId, base64, and mimetype are required' });
|
||||
}
|
||||
|
||||
// If it is an OGG audio file being sent, convert it to MP3 so the headless browser can decode it and calculate duration
|
||||
if (mimetype && (mimetype.includes('audio/ogg') || mimetype.includes('ogg'))) {
|
||||
try {
|
||||
console.log(`[WS] Converting outgoing OGG audio to MP3 for Puppeteer compatibility...`);
|
||||
const mp3Base64 = await convertOggToMp3(base64);
|
||||
base64 = mp3Base64;
|
||||
mimetype = 'audio/mp3';
|
||||
filename = 'voice_note.mp3';
|
||||
} catch (err) {
|
||||
console.error(`[WS] Outgoing audio conversion failed (sending raw Ogg instead):`, err.message);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
const { MessageMedia } = require('whatsapp-web.js');
|
||||
const media = new MessageMedia(mimetype, base64, filename || 'file');
|
||||
|
||||
Reference in New Issue
Block a user