From 2ca318878de2f22751319b2b7ccac84644583173 Mon Sep 17 00:00:00 2001 From: MartinCupela <32706194+MartinCupela@users.noreply.github.com> Date: Fri, 21 Jun 2024 12:43:01 +0200 Subject: [PATCH] feat: load lazily mp3 encoding library for audio recorder (#2432) --- src/components/MediaRecorder/transcode/mp3.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/MediaRecorder/transcode/mp3.ts b/src/components/MediaRecorder/transcode/mp3.ts index b0066862f..ada9c310c 100644 --- a/src/components/MediaRecorder/transcode/mp3.ts +++ b/src/components/MediaRecorder/transcode/mp3.ts @@ -1,4 +1,3 @@ -import { Mp3Encoder } from '@breezystack/lamejs'; import { renderAudio, toAudioBuffer } from './audioProcessing'; const ENCODING_BIT_RATE = 128; // kbps; @@ -22,10 +21,11 @@ const splitDataByChannel = (audioBuffer: AudioBuffer) => ); export async function encodeToMp3(file: File, sampleRate: number) { + const lameJs = await import('@breezystack/lamejs'); const audioBuffer = await renderAudio(await toAudioBuffer(file), sampleRate); const channelCount = audioBuffer.numberOfChannels; const dataByChannel = splitDataByChannel(audioBuffer); - const mp3Encoder = new Mp3Encoder(channelCount, sampleRate, ENCODING_BIT_RATE); + const mp3Encoder = new lameJs.Mp3Encoder(channelCount, sampleRate, ENCODING_BIT_RATE); const dataBuffer: Int8Array[] = []; let remaining = dataByChannel[0].length;