From 941664eae67f117f857a5f8ff3eb8be8f5dbf662 Mon Sep 17 00:00:00 2001 From: liamcottle Date: Mon, 3 Jun 2024 14:24:07 +1200 Subject: [PATCH] add ui to preview encoded audio before sending it --- public/index.html | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/public/index.html b/public/index.html index ee1eaf7..576df80 100644 --- a/public/index.html +++ b/public/index.html @@ -667,15 +667,30 @@
-
- Audio Recording - {{ formatBytes(newMessageAudio.audio_blob.size) }} + +
+ + +
+ +
+ + +
+ {{ formatBytes(newMessageAudio.audio_blob.size) }} +
+
+ +
+
@@ -2418,7 +2433,7 @@ } }, - stopRecordingAudioAttachment: function() { + async stopRecordingAudioAttachment() { // clear audio recording timer clearInterval(this.audioAttachmentRecordingTimer); @@ -2437,10 +2452,20 @@ return; } + // decode codec2 audio back to wav so we can show a preview audio player before user sends it + const decoded = await Codec2Lib.runDecode("1200", new Uint8Array(audio)); + + // convert decoded codec2 to wav audio and create a blob + const wavAudio = await Codec2Lib.rawToWav(decoded); + const wavBlob = new Blob([wavAudio], { + type: "audio/wav", + }); + // update message audio attachment this.newMessageAudio = { audio_mode: 0x04, // hardcoded to LXMF.AM_CODEC2_1200 for now audio_blob: new Blob([audio]), + audio_wav_url: URL.createObjectURL(wavBlob), }; },