TooTallNate / node-lame

Node.js native bindings to libmp3lame & libmpg123
MIT License
567 stars 113 forks source link

Trying to get node-lame to work under node-red #69

Open dennisnotojr opened 7 years ago

dennisnotojr commented 7 years ago

used npm install lame in my package.setting to get it installed. Writing a function to take msg.payload which is an object that contains the wav file contents to encode into a mp3. When trying to create a new instance of lame.Encoder, I get the following error:TypeError: Cannot read property 'Encoder' of undefined. Can't get past the creation of lame.Encoder!!! Even after I get past this problem, hoping the encoder will take a java object in and out.

here is the code in the node red function node:

var lame = global.get('lame');

(can't use require in nodes, must set up as a global function in node-red setting) and then call global.get.

// create the Encoder instance var encoder = new lame.Encoder({ // input channels: 1, // 2 channels (left and right) bitDepth: 16, // 16-bit samples sampleRate: 22050, // 44,100 Hz sample rate

// output bitRate: 48, outSampleRate: 16000, // mode: lame.STEREO // STEREO (default), JOINTSTEREO, DUALCHANNEL or MONO });

// raw PCM data from stdin gets piped into the encoder var newmsg = {filename: msg.filename};

var input = msg.payload; input.pipe(encoder);

//node.log("got past first stage");

// the generated MP3 file gets piped to stdout encoder.pipe(newmsg.payload);

return newmsg;

LinusU commented 7 years ago

This means that lame is undefined. What is global.get? and why can't you use require?

dennisnotojr commented 7 years ago

Inside of node-red which is an ESB of sorts. you can't use require. You have to set up modules with a call to global.get so the model is known to all flows. Node-Red uses Node.js as a container and I was hoping I could leverage this npm to encode stuff. Looks like there are some incompatibilities with this code and node red's use of node.js.

See http://nodered.org/docs/writing-functions - look for "os Module".

Den