I want to read an audi file with Node.js, decode it to PCM and encode it as a MP3. I'm using node-lame to do the en-/decoding, but unfortunately I get the following error:
/Users/Jon/streaming test/node_modules/lame/lib/encoder.js:191
write(output);
^
TypeError: string is not a function
at cb (/Users/Jon/streaming test/node_modules/lame/lib/encoder.js:191:7)
My code for the encoding and decoding:
var filename = './beautifullie.mp3';
var decoder = lame.Decoder();
var encoder = lame.Encoder({channels: 2, bitDepth: 16, sampleRate: 44100});
fs.createReadStream(filename).pipe(decoder);
decoder.on('format', function(format) {
console.log('Decoding .. '+JSON.stringify(format));
decoder.pipe(encoder);
});
encoder.on("data", function(data) {
console.log('Sending..');
//sendData(data);
});
You can find the file that throws the error here: https://github.com/TooTallNate/node-lame/blob/master/lib/encoder.js
Here's a work-around that worked for me (running node.js 0.10.3 on a Ubuntu machine). Maybe someone knows why require('stream').Transform won't work properly - the write argument in _transform function seem to be a string containing 'utf8'. I'm a total newbie when it comes to javascript and node.js...
In the beginning of decoder.js and encoder.js there is an if statement
if (!Transform) Transform = require('readable-stream/transform');
Remove the if and just set the Transform variable like this:
Transform = require('readable-stream/transform');