This module changes the volume of a given PCM data stream. At the moment only signed 16bit PCM data is supported, also I'm not quite sure about this as my knowledge about PCM is very limited. I don't know whether this is the right way to do things. Feel free to contact me/open a pull request if you want to add something.
npm install pcm-volume or clone from GitHub and
Pipe an existing stream into an instance of pcm-volume. You can get a PCM-stream from node-lame for example.
This example reads the file music.mp3 and changes the volume to 50% after 5seconds.
var Speaker = ;var lame = ;var fs = ;var volume = ;var readable = fs;// see node-lame documentation for more informationvar decoder =channels: 2bitDepth: 16sampleRate: 44100bitRate: 128outSampleRate: 22050mode: lameSTEREO;// Initialize speakervar speaker = ;// Create a volume instancevar v = ;// Wait 5s, then change the volume to 50%v; // pipe volume to speakerdecoder; // pipe PCM data to volumereadable; // pipe file input to decoder
pcm-volume is a Transform Stream (see http://nodejs.org/api/stream.html#stream_class_stream_transform_1 for more information). Pipe in your PCM data and pipe out PCM data with a different volume. Use setVolume(v) to set the volume (v is a float between 0 and roughly 1.5 also you can go higher but it sounds like crap).