What is it?
lib/ contains library files.
Mp3LameEncoder.min.js.mem: memory initializer data for Mp3LameEncoder.min.js
Uncompressesd library is a single file. You can use it from both HTML and Web Worker.
- from HTML:
- from Worker:
Using minified library is same way. But you must pay attention to memory initializer location.
- from HTML: default directory is same as HTML which loads Mp3LameEncoder.min.js
- from Worker: default directory is same as Mp3LameEncoder.min.js path
To change memory initializer path from HTML:
encoder = new Mp3LameEncoder(sampleRate, bitRate)
Create an encoder object.
samleRate: sampling rate [Hz]
bitRate: MP3 bit rate [kbps]
- encoder object
Actual bit rate is set as follows (at 44100Hz).
.. 72 -> 64 73.. 89 -> 80 90..104 -> 96 105..120 -> 112 121..144 -> 128 145..176 -> 160 177..208 -> 192 209..240 -> 224 241..288 -> 256 289.. -> 320
Current implementation supports LAME CBR encoding only.
Encode audio buffers.
buffers: array of sample buffers (
buffers must be an array of two Float32Array audio data (separate strereo, range = [-1, 1]). It supports stream (incremental) processing. Sample buffers are processed to MP3 stream and appended to internal data.
blob = encoder.finish([mimeType])
Finish encoding and get MP3 as a Blob.
mimeType(optional): MIME type (default =
- Blob object
.finish(), all internal data is cleared (to avoid resource leak). You must create a new encoder object to encode another audio data.
Cancel encoding and clear all internal data.
You should call
.cancel() manually to avoid resource leak when recording is canceled (encoder's internal memory is not deallocated by unbinding an object variable).
Emscripten and ruby are required to build the library.
Download and extract LAME, build library files (see Rakefile for more details).