- Description:
Convert audio to MP3.
- Source:
- Copyright:
- Meirza
- Meirza
- License:
- http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
Convert audio to MP3.
Members
(static, constant) convertMp3
- Description:
Main function to handle the entire process of converting an audio file to MP3 format.
- Source:
Main function to handle the entire process of converting an audio file to MP3 format.
Example
const mp3Data = await convertMp3('audio-source.wav', 192);
window.console.log(mp3Data); // Logs the ArrayBuffer with MP3 data.
Methods
(inner) convertAudioBuffer(lamejs, channels, sampleRate, bitRate, left, rightopt) → {Blob}
- Description:
Converts an AudioBuffer to MP3 format using lamejs.
- Source:
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
lamejs |
Object | The lamejs library object. |
||
channels |
number | The number of audio channels (1 for mono, 2 for stereo). |
||
sampleRate |
number | The sample rate of the audio (e.g., 44100 Hz). |
||
bitRate |
number | The bitrate (in kbps) to encode the MP3. |
||
left |
Int16Array | The PCM data for the left channel. |
||
right |
Int16Array |
<optional> |
null
|
The PCM data for the right channel (optional for stereo). |
Returns:
- A Blob containing the MP3 audio data.
- Type
- Blob
(inner) extractPCM(audioBuffer) → {Array.<Int16Array>}
- Description:
Extract Pulse Code Modulation (PCM) data from an AudioBuffer to get raw channel data.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
audioBuffer |
AudioBuffer | The AudioBuffer containing the audio data. |
Returns:
The PCM data for each channel.
- Type
- Array.<Int16Array>
(async, inner) getAudioBuffer(sourceUrl) → {Promise.<AudioBuffer>}
- Description:
Fetches and decodes the audio data from a given URL into an AudioBuffer.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
sourceUrl |
string | The URL of the source audio file. |
Returns:
- A promise that resolves with the decoded AudioBuffer object.
- Type
- Promise.<AudioBuffer>