feat: Added conversion of audios for sending recorded audio

This commit is contained in:
Davidson Gomes 2023-06-11 10:36:59 -03:00
parent 2b2cc2effc
commit 75b8bcb853
2 changed files with 13 additions and 4 deletions

View File

@ -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(

Binary file not shown.