fix: install lamejs from GitHub repo for proper browser support

Switched from npm package to GitHub repo (github:zhuker/lamejs) which
includes the proper browser build. Reverted to simple dynamic import.

Fixes MP3 export MPEGMode reference error.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-11-19 08:11:46 +01:00
parent 77916d4d07
commit d5c84d35e4
3 changed files with 9 additions and 33 deletions

View File

@@ -129,31 +129,6 @@ export function downloadArrayBuffer(
URL.revokeObjectURL(url);
}
/**
* Load lamejs library dynamically
*/
async function loadLamejs(): Promise<any> {
// Check if already loaded
if (typeof window !== 'undefined' && (window as any).lamejs) {
return (window as any).lamejs;
}
// Load the script from node_modules
return new Promise((resolve, reject) => {
const script = document.createElement('script');
script.src = '/node_modules/.pnpm/lamejs@1.2.1/node_modules/lamejs/lame.min.js';
script.onload = () => {
if ((window as any).lamejs) {
resolve((window as any).lamejs);
} else {
reject(new Error('lamejs failed to load'));
}
};
script.onerror = () => reject(new Error('Failed to load lamejs script'));
document.head.appendChild(script);
});
}
/**
* Convert an AudioBuffer to MP3
*/
@@ -161,8 +136,8 @@ export async function audioBufferToMp3(
audioBuffer: AudioBuffer,
options: ExportOptions = { format: 'mp3', bitrate: 192 }
): Promise<ArrayBuffer> {
// Load lamejs library
const lamejs = await loadLamejs();
// Dynamically import lamejs from GitHub repo (has proper browser build)
const lamejs = await import('lamejs');
const { bitrate = 192, normalize } = options;
const numberOfChannels = Math.min(audioBuffer.numberOfChannels, 2); // MP3 supports max 2 channels