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:
@@ -129,31 +129,6 @@ export function downloadArrayBuffer(
|
|||||||
URL.revokeObjectURL(url);
|
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
|
* Convert an AudioBuffer to MP3
|
||||||
*/
|
*/
|
||||||
@@ -161,8 +136,8 @@ export async function audioBufferToMp3(
|
|||||||
audioBuffer: AudioBuffer,
|
audioBuffer: AudioBuffer,
|
||||||
options: ExportOptions = { format: 'mp3', bitrate: 192 }
|
options: ExportOptions = { format: 'mp3', bitrate: 192 }
|
||||||
): Promise<ArrayBuffer> {
|
): Promise<ArrayBuffer> {
|
||||||
// Load lamejs library
|
// Dynamically import lamejs from GitHub repo (has proper browser build)
|
||||||
const lamejs = await loadLamejs();
|
const lamejs = await import('lamejs');
|
||||||
|
|
||||||
const { bitrate = 192, normalize } = options;
|
const { bitrate = 192, normalize } = options;
|
||||||
const numberOfChannels = Math.min(audioBuffer.numberOfChannels, 2); // MP3 supports max 2 channels
|
const numberOfChannels = Math.min(audioBuffer.numberOfChannels, 2); // MP3 supports max 2 channels
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"clsx": "^2.1.1",
|
"clsx": "^2.1.1",
|
||||||
"fflate": "^0.8.2",
|
"fflate": "^0.8.2",
|
||||||
"lamejs": "^1.2.1",
|
"lamejs": "github:zhuker/lamejs",
|
||||||
"lucide-react": "^0.553.0",
|
"lucide-react": "^0.553.0",
|
||||||
"next": "^16.0.0",
|
"next": "^16.0.0",
|
||||||
"react": "^19.0.0",
|
"react": "^19.0.0",
|
||||||
|
|||||||
11
pnpm-lock.yaml
generated
11
pnpm-lock.yaml
generated
@@ -15,8 +15,8 @@ importers:
|
|||||||
specifier: ^0.8.2
|
specifier: ^0.8.2
|
||||||
version: 0.8.2
|
version: 0.8.2
|
||||||
lamejs:
|
lamejs:
|
||||||
specifier: ^1.2.1
|
specifier: github:zhuker/lamejs
|
||||||
version: 1.2.1
|
version: https://codeload.github.com/zhuker/lamejs/tar.gz/582bbba6a12f981b984d8fb9e1874499fed85675
|
||||||
lucide-react:
|
lucide-react:
|
||||||
specifier: ^0.553.0
|
specifier: ^0.553.0
|
||||||
version: 0.553.0(react@19.2.0)
|
version: 0.553.0(react@19.2.0)
|
||||||
@@ -1384,8 +1384,9 @@ packages:
|
|||||||
keyv@4.5.4:
|
keyv@4.5.4:
|
||||||
resolution: {integrity: sha512-oxVHkHR/EJf2CNXnWxRLW6mg7JyCCUcG0DtEGmL2ctUo1PNTin1PUil+r/+4r5MpVgC/fn1kjsx7mjSujKqIpw==}
|
resolution: {integrity: sha512-oxVHkHR/EJf2CNXnWxRLW6mg7JyCCUcG0DtEGmL2ctUo1PNTin1PUil+r/+4r5MpVgC/fn1kjsx7mjSujKqIpw==}
|
||||||
|
|
||||||
lamejs@1.2.1:
|
lamejs@https://codeload.github.com/zhuker/lamejs/tar.gz/582bbba6a12f981b984d8fb9e1874499fed85675:
|
||||||
resolution: {integrity: sha512-s7bxvjvYthw6oPLCm5pFxvA84wUROODB8jEO2+CE1adhKgrIvVOlmMgY8zyugxGrvRaDHNJanOiS21/emty6dQ==}
|
resolution: {tarball: https://codeload.github.com/zhuker/lamejs/tar.gz/582bbba6a12f981b984d8fb9e1874499fed85675}
|
||||||
|
version: 1.2.1
|
||||||
|
|
||||||
language-subtag-registry@0.3.23:
|
language-subtag-registry@0.3.23:
|
||||||
resolution: {integrity: sha512-0K65Lea881pHotoGEa5gDlMxt3pctLi2RplBb7Ezh4rRdLEOtgi7n4EwK9lamnUCkKBqaeKRVebTq6BAxSkpXQ==}
|
resolution: {integrity: sha512-0K65Lea881pHotoGEa5gDlMxt3pctLi2RplBb7Ezh4rRdLEOtgi7n4EwK9lamnUCkKBqaeKRVebTq6BAxSkpXQ==}
|
||||||
@@ -3412,7 +3413,7 @@ snapshots:
|
|||||||
dependencies:
|
dependencies:
|
||||||
json-buffer: 3.0.1
|
json-buffer: 3.0.1
|
||||||
|
|
||||||
lamejs@1.2.1:
|
lamejs@https://codeload.github.com/zhuker/lamejs/tar.gz/582bbba6a12f981b984d8fb9e1874499fed85675:
|
||||||
dependencies:
|
dependencies:
|
||||||
use-strict: 1.0.1
|
use-strict: 1.0.1
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user