Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Update the voice note format to MP3 to fix the delivery issues #9448

Merged
merged 4 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,21 @@ import { convertWavToMp3 } from './utils/mp3ConversionUtils';

WaveSurfer.microphone = MicrophonePlugin;

const RECORDER_CONFIG = {
[AUDIO_FORMATS.WAV]: {
audioMimeType: 'audio/wav',
audioWorkerURL: waveWorker,
},
[AUDIO_FORMATS.MP3]: {
audioMimeType: 'audio/wav',
audioWorkerURL: waveWorker,
},
[AUDIO_FORMATS.OGG]: {
audioMimeType: 'audio/ogg',
audioWorkerURL: encoderWorker,
},
};

export default {
name: 'WootAudioRecorder',
mixins: [alertMixin],
Expand Down Expand Up @@ -94,14 +109,7 @@ export default {
audioSampleRate: 48000,
audioBitRate: 128,
audioEngine: 'opus-recorder',
...(this.audioRecordFormat === AUDIO_FORMATS.WAV && {
audioMimeType: 'audio/wav',
audioWorkerURL: waveWorker,
}),
...(this.audioRecordFormat === AUDIO_FORMATS.OGG && {
audioMimeType: 'audio/ogg',
audioWorkerURL: encoderWorker,
}),
...RECORDER_CONFIG[this.audioRecordFormat],
},
},
},
Expand Down Expand Up @@ -139,7 +147,11 @@ export default {
methods: {
deviceReady() {
if (this.player.record().engine instanceof OpusRecorderEngine) {
if (this.audioRecordFormat === AUDIO_FORMATS.WAV) {
if (
[AUDIO_FORMATS.WAV, AUDIO_FORMATS.MP3].includes(
this.audioRecordFormat
)
) {
this.player.record().engine.audioType = 'audio/wav';
}
}
Expand All @@ -154,13 +166,12 @@ export default {
async finishRecord() {
let recordedContent = this.player.recordedData;
let fileName = this.player.recordedData.name;
if (this.isAWhatsAppChannel) {
let type = this.player.recordedData.type;
if (this.audioRecordFormat === AUDIO_FORMATS.MP3) {
recordedContent = await convertWavToMp3(this.player.recordedData);
fileName = `${getUuid()}.mp3`;
type = AUDIO_FORMATS.MP3;
}
const type = !this.isAWhatsAppChannel
? this.player.recordedData.type
: 'audio/mp3';
const file = new File([recordedContent], fileName, { type });
this.fireRecorderBlob(file);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
v-if="showAudioRecorderEditor"
ref="audioRecorderInput"
:audio-record-format="audioRecordFormat"
:is-a-whats-app-channel="isAWhatsAppChannel"
@state-recorder-progress-changed="onStateProgressRecorderChanged"
@state-recorder-changed="onStateRecorderChanged"
@finish-record="onFinishRecorder"
Expand Down Expand Up @@ -502,7 +501,10 @@ export default {
return `draft-${this.conversationIdByRoute}-${this.replyType}`;
},
audioRecordFormat() {
if (this.isAPIInbox || this.isATelegramChannel) {
if (this.isAWhatsAppChannel || this.isATelegramChannel) {
return AUDIO_FORMATS.MP3;
}
if (this.isAPIInbox) {
return AUDIO_FORMATS.OGG;
}
return AUDIO_FORMATS.WAV;
Expand Down Expand Up @@ -1250,6 +1252,7 @@ export default {
}
}
}

.send-button {
@apply mb-0;
}
Expand All @@ -1274,6 +1277,7 @@ export default {

.emoji-dialog--rtl {
@apply left-[unset] -right-80;

&::before {
transform: rotate(90deg);
filter: drop-shadow(0px 4px 4px rgba(0, 0, 0, 0.08));
Expand Down
1 change: 1 addition & 0 deletions app/javascript/shared/constants/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export const CSAT_RATINGS = [
export const AUDIO_FORMATS = {
WEBM: 'audio/webm',
OGG: 'audio/ogg',
MP3: 'audio/mp3',
WAV: 'audio/wav',
};

Expand Down