Skip to content

Commit

Permalink
feat: load lazily mp3 encoding library for audio recorder (#2432)
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinCupela authored Jun 21, 2024
1 parent 977ec39 commit 2ca3188
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/components/MediaRecorder/transcode/mp3.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Mp3Encoder } from '@breezystack/lamejs';
import { renderAudio, toAudioBuffer } from './audioProcessing';

const ENCODING_BIT_RATE = 128; // kbps;
Expand All @@ -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;
Expand Down

0 comments on commit 2ca3188

Please sign in to comment.