From 75b8bcb8531bc65f22f3777327d667075d50d3c0 Mon Sep 17 00:00:00 2001 From: Davidson Gomes Date: Sun, 11 Jun 2023 10:36:59 -0300 Subject: [PATCH] feat: Added conversion of audios for sending recorded audio --- src/whatsapp/services/whatsapp.service.ts | 17 +++++++++++++---- temp/audio.opus | Bin 97554 -> 97554 bytes 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/whatsapp/services/whatsapp.service.ts b/src/whatsapp/services/whatsapp.service.ts index 09067b1e..324bbabe 100644 --- a/src/whatsapp/services/whatsapp.service.ts +++ b/src/whatsapp/services/whatsapp.service.ts @@ -1112,13 +1112,22 @@ export class WAStartupService { } private async processAudio(audio: string) { - const outputAudio = `${join(process.cwd(), 'temp', 'audio.opus')}`; + let tempAudioPath: string; + let outputAudio: string; - const response = await axios.get(audio, { responseType: 'arraybuffer' }); + if (isURL(audio)) { + outputAudio = `${join(process.cwd(), 'temp', 'audio.opus')}`; + tempAudioPath = `${join(process.cwd(), 'temp', 'audio.mp3')}`; - const tempAudioPath = `${join(process.cwd(), 'temp', 'audio.mp3')}`; + const response = await axios.get(audio, { responseType: 'arraybuffer' }); + fs.writeFileSync(tempAudioPath, response.data); + } else { + outputAudio = `${join(process.cwd(), 'temp', 'audio.opus')}`; + tempAudioPath = `${join(process.cwd(), 'temp', 'audio.mp3')}`; - fs.writeFileSync(tempAudioPath, response.data); + const audioBuffer = Buffer.from(audio, 'base64'); + fs.writeFileSync(tempAudioPath, audioBuffer); + } return new Promise((resolve, reject) => { exec( diff --git a/temp/audio.opus b/temp/audio.opus index ab144779ef7e819e0ccfd86492606138bb949ced..4a6b14280d54853b07506a4228d83e27345534a7 100644 GIT binary patch delta 161 zcmbRAi*?d3Rw@7V^k4=i1}Lx-e)|f459WguTiw2$ zvT=!(Cs=?PC~)o~d%)&bo__+sA}l}=o9-itn?KFE<^dLA1&SaVh0MXO61Adu2{nOkplpr7&tuu delta 161 zcmbRAi*?d3Rw@7V^k4=i1}G5sl3EI4=4{#DIZ;ZP2gGLt^4WB1r6zj%gZUuE@(-Tv z-?+re6D+_C6woq1&$IcJ=br$u2n$d|OrnOc dM}C>UT~3$ryBk;$J5b1Y^=7y2iY1I6IRK7tEu8=W