You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
For all your async streaming MP3 encoding/decoding needs, there'snode-lame!This module hooks into libmp3lame, the library that thelame command uses, toprovideEncoder andDecoder streams to NodeJS.
Installation
node-lame comes bundled with its own copy oflibmp3lame andlibmpg123, sothere's no need to have them installed on your system.
Simply compile and installnode-lame usingnpm:
$ npm install @flat/lame
Example
Here's an example of using@flat/node-lame to encode some raw PCM data coming fromprocess.stdin to an MP3 file that gets piped toprocess.stdout:
varlame=require('@flat/lame');// create the Encoder instancevarencoder=newlame.Encoder({// inputchannels:2,// 2 channels (left and right)bitDepth:16,// 16-bit samplessampleRate:44100,// 44,100 Hz sample rate// outputbitRate:128,outSampleRate:22050,mode:lame.STEREO// STEREO (default), JOINTSTEREO, DUALCHANNEL or MONO});// raw PCM data from stdin gets piped into the encoderprocess.stdin.pipe(encoder);// the generated MP3 file gets piped to stdoutencoder.pipe(process.stdout);
See theexamples directory for some more example code.
API
Decoder class
TheDecoder class is aStream subclass that accepts MP3 data written to it,and outputs raw PCM data. It also emits a"format" event when the format ofthe MP3 file is determined (usually right at the beginning).
Encoder class
TheEncoder class is aStream subclass that accepts raw PCM data written toit, and outputs a valid MP3 file. You must specify the PCM data format whencreating the encoder instance. Only 16-bit signed samples are currentlysupported (rescale before passing to the encoder if necessary)...