Skip to content

Commit

Permalink
[FIX] Unable to send voice recording to Whatsapp (#26276)
Browse files Browse the repository at this point in the history
  • Loading branch information
murtaza98 committed Aug 2, 2022
1 parent 5c2b1ad commit 8bf550d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ Template.messageBoxAudioMessage.events({
const { rid, tmid } = this;
const blob = await cancelRecording(instance, rid, tmid);

await fileUpload([{ file: blob, type: 'video', name: `${t('Audio record')}.mp3` }], { input: blob }, { rid, tmid });
const fileName = `${t('Audio record')}.mp3`;
const file = new File([blob], fileName, { type: 'audio/mpeg' });

await fileUpload([{ file, type: 'audio/mpeg', name: fileName }], { input: blob }, { rid, tmid });
},
});
5 changes: 4 additions & 1 deletion apps/meteor/app/ui/client/lib/recorderjs/audioEncoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ class AudioEncoder extends Emitter {
handleWorkerMessage = (event) => {
switch (event.data.command) {
case 'end': {
const blob = new Blob(event.data.buffer, { type: 'audio/mpeg' });
// prepend mp3 magic number to the buffer
const magicNoPrefix = new Int8Array([73, 68, 51, 3, 0, 0, 0, 0, 0, 0]);
const bufferWithMagicNo = [magicNoPrefix, ...event.data.buffer];
const blob = new Blob(bufferWithMagicNo, { type: 'audio/mpeg' });
this.emit('encoded', blob);
this.worker.terminate();
break;
Expand Down

0 comments on commit 8bf550d

Please sign in to comment.