Enviar audio pelo wppconnect

Tô tentando enviar o audio do meu front para o back para depois mandar em formato de arquivo para a lib, segue meu código:

Primero crio o audio e envio do front para o back

const btn = document.getElementById('btn-audio');
let chunks = []
let stream
let mediaRecoder

btn.onclick = () => {
    OnRecoder ? stopListening() : startListening()
}

function startListening() {
    if (navigator.mediaDevices) {
        navigator.mediaDevices.getUserMedia({ audio: true })
            .then(mediaStream => {
                stream = mediaStream
                let mr = new MediaRecorder(stream)
                mediaRecoder = mr
                if (!OnRecoder) {
                    mediaRecoder.start()
                    OnRecoder = true
                }

                mediaRecoder.ondataavailable = (e) => {
                    chunks.push(e.data);
                };
            })
    }
}

function stopListening() {

    mediaRecoder.stop()
    OnRecoder = false

    mediaRecoder.onstop = (e) => {
        const blob = new Blob(chunks, { type: "audio/ogg; codecs=opus" })
       
        chunks = []

        const reader = new FileReader()
        reader.readAsDataURL(blob)

        reader.onloadend = async () => {
            await fetch('/postAudio', {
                method: "POST",
                headers: {
                    'Content-Type': 'application/json',
                },
                body: JSON.stringify({ data: reader.result })
            })
                .then(response => {
                    response.ok ? alert('deu certo') : alert('deu errado')
                })
        };

        stream.getTracks().forEach(tack => tack.stop())
    }
}

depois recebo no back, converto em audio para salvar o arquivo

router.post('/postAudio', jsonParser, async (req, res) => {
    var body = req.body
    let date = Date.now()
    console.log(body);

    let savedFile = await saveBase64File(`audio_${date}`, body.data)
    body.filepath = savedFile.filepath
    body.filename = savedFile.filename
    console.log(body);
    
    emiter.emit('sendNewAudioMessage', body)

    res.status(200).send({ audio: 'Audio recebido' })
})

async function saveBase64File(filename, base64Data) {
    let split64 = base64Data.split(';')
    let extensao = split64[0].split('/')[1]
    //console.log(base64Data.split(',')[1]);

    try {
        let folderPath = path.join(__dirname, '..', '..', 'mideas');

        try {
            await fs1.access(folderPath);
        } catch (error) {
            await fs1.mkdir(folderPath);
        }

        const filepath = path.join(__dirname, '..', '..', 'mideas', `${filename}.${extensao}`);

        try {
            await fs1.access(filepath);
            console.log('Arquivo já existe, não é necessário salvar novamente:', filepath);
            return { filepath, filename };
        } catch (error) {
            await fs1.writeFile(filepath, base64Data.split(',')[1], 'base64');
            return {
                filepath: filepath,
                filename: `${filename}.${extensao}`
            };
        }
    } catch (error) {
        console.error(`ERRO AO SALVAR ARQUIVO:\n ${error}`);
        return { filepath: false, filename: false };
    }
}

e por ultimo envio:

emiter.on('sendNewAudioMessage', (object) => {
            console.log('aqui');
            client.sendFile(object.to, object.filePath)
})

Porém ele sempre dá erro, poderiam me ajudar a entender se é meu base64? Desde já muito grato!

Qual erro da?

este:

to: '559984604153@c.us',
  chunks: [],
  filepath: 'C:\\Users\\Flavio\\Documents\\Cloud-Drive\\vacine\\mideas\\audio_1723250387415.ogg',
  filename: 'audio_1723250387415.ogg'
}
error:    Unhandled Rejection: InvalidMediaCheckRepairFailedType: {"name":"InvalidMediaCheckRepairFailedType","stack":"InvalidMediaCheckRepairFailedType\n    at a.d [as constructor] (https://static.whatsapp.net/rsrc.php/v3irym4/yd/l/rt/GuH1ezaDSn-.js?_nc_x=Ij3Wp8lg5Kz:33:217)\n    at new a (https://static.whatsapp.net/rsrc.php/v3irym4/yd/l/rt/GuH1ezaDSn-.js?_nc_x=Ij3Wp8lg5Kz:34:1016)\n    at Object.<anonymous> (https://static.whatsapp.net/rsrc.php/v3iHfY4/yL/l/rt/Z7MI8BI65Wg.js?_nc_x=Ij3Wp8lg5Kz:854:6729)\n    at Generator.next (<anonymous>)\n    at h (https://static.whatsapp.net/rsrc.php/v3i3pB4/y1/l/rt/YZtObq2M89193qFpVoVeCadDhlRhWcaNovsWqehdEtWw.js?_nc_x=Ij3Wp8lg5Kz:179:125)\n    at g (https://static.whatsapp.net/rsrc.php/v3i3pB4/y1/l/rt/YZtObq2M89193qFpVoVeCadDhlRhWcaNovsWqehdEtWw.js?_nc_x=Ij3Wp8lg5Kz:179:349)"}
    at C:\Users\Flavio\Documents\Cloud-Drive\vacine\node_modules\@wppconnect-team\wppconnect\dist\api\helpers\evaluate-and-return.js:107:31
    at step (C:\Users\Flavio\Documents\Cloud-Drive\vacine\node_modules\@wppconnect-team\wppconnect\dist\api\helpers\evaluate-and-return.js:49:23)
    at Object.next (C:\Users\Flavio\Documents\Cloud-Drive\vacine\node_modules\@wppconnect-team\wppconnect\dist\api\helpers\evaluate-and-return.js:30:53)
    at fulfilled (C:\Users\Flavio\Documents\Cloud-Drive\vacine\node_modules\@wppconnect-team\wppconnect\dist\api\helpers\evaluate-and-return.js:21:58)
JS Stack: InvalidMediaCheckRepairFailedType
    at a.d [as constructor] (https://static.whatsapp.net/rsrc.php/v3irym4/yd/l/rt/GuH1ezaDSn-.js?_nc_x=Ij3Wp8lg5Kz:33:217)
    at new a (https://static.whatsapp.net/rsrc.php/v3irym4/yd/l/rt/GuH1ezaDSn-.js?_nc_x=Ij3Wp8lg5Kz:34:1016)
    at Object.<anonymous> (https://static.whatsapp.net/rsrc.php/v3iHfY4/yL/l/rt/Z7MI8BI65Wg.js?_nc_x=Ij3Wp8lg5Kz:854:6729)
    at Generator.next (<anonymous>)
    at h (https://static.whatsapp.net/rsrc.php/v3i3pB4/y1/l/rt/YZtObq2M89193qFpVoVeCadDhlRhWcaNovsWqehdEtWw.js?_nc_x=Ij3Wp8lg5Kz:179:125)
    at g (https://static.whatsapp.net/rsrc.php/v3i3pB4/y1/l/rt/YZtObq2M89193qFpVoVeCadDhlRhWcaNovsWqehdEtWw.js?_nc_x=Ij3Wp8lg5Kz:179:349)
Function: function (_a) { return __awaiter(_this, [_a], void 0, function (_b) {
                            var result;
                            var _c;
                            var to = _b.to, base64 = _b.base64, filename = _b.filename, caption = _b.caption, quotedMessageId = _b.quotedMessageId, messageId = _b.messageId;
                            return __generator(this, function (_d) {
                                switch (_d.label) {
                                    case 0: return [4 /yield/, WPP.chat.sendFileMessage(to, base64, {
                                            type: 'audio',
                                            isPtt: true,
                                            filename: filename,
                                            caption: caption,
                                            quotedMsg: quotedMessageId,
                                            waitForAck: true,
                                            messageId: messageId,
                                        })];
                                    case 1:
                                        result = _d.sent();
                                        _c = {
                                            ack: result.ack,
                                            id: result.id
                                        };
                                        return [4 /yield/, result.sendMsgResult];
                                    case 2: return [2 /return/, (_c.sendMsgResult = _d.sent(),
                                            _c)];
                                }
                            });
                        }); }

Mas tbm tem um detalhe, por algum motivo meu base64 está codifcado como video, poderia me dar uma luz de como resolvo isso?

E além disso meu audio fica assim, sem exibir o tempo total:

image

Fala galera, passando pra finalizar o tópico, o erro era basicamente pq pelo chrome só gerava base64 do tipo webm, sendo assim, passei a enviar o base64 e converter com ffmpeg (Esse aqui) pesquisei por fnExtractSoundToMP3, o resto é só felicidade!

Fica o código para quem vier depois com a mesma dúvida, falta refatorar e ajusar para outras extensões, ma dá pra ter um começo!

async function saveBase64File(filename, base64Data) {
    let split64 = base64Data.split(';');
    let extensao = split64[0].split('/')[1];

    try {
        let folderPath = path.join(__dirname, '..', '..', 'mideas');

        try {
            await fs1.access(folderPath);
        } catch (error) {
            await fs1.mkdir(folderPath);
        }

        var filepath = path.join(__dirname, '..', '..', 'mideas', `${filename}.${extensao}`);

        try {
            await fs1.access(filepath);
            console.log('Arquivo já existe, não é necessário salvar novamente:', filepath);
            return { filepath, filename };
        } catch (error) {
            await fs1.writeFile(filepath, base64Data.split(',')[1], 'base64');

            try {
                var process = new ffmpeg(filepath);
                await process.then((video) => {
                    return new Promise((resolve, reject) => {
                        video.fnExtractSoundToMP3(filepath.replace('.webm', '.mp3'), (erro, file) => {
                            if (erro) {
                                reject(erro);
                            } else {
                                fs1.unlink(filepath)
                                    .then(() => {
                                        resolve(file);
                                    })
                                    .catch(reject);
                            }
                        });
                    });
                }).then((newFilepath) => {
                    filepath = newFilepath;
                });
            } catch (ffmpegError) {
                console.log(ffmpegError);
            }

            return {
                filepath: filepath,
                filename: `${filename}.${extensao}`
            };
        }
    } catch (error) {
        console.error(`ERRO AO SALVAR ARQUIVO:\n ${error}`);
        return { filepath: false, filename: false };
    }
}