Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
dennisnotojr opened this issue Oct 13, 2016 · 2 comments
Open

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

dennisnotojr opened this issue Oct 13, 2016 · 2 comments

Comments

@dennisnotojr
Copy link

dennisnotojr commented Oct 13, 2016

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
Copy link
Collaborator

LinusU commented Oct 14, 2016

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

@dennisnotojr
Copy link
Author

dennisnotojr commented Oct 14, 2016

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

@dennisnotojr dennisnotojr changed the title Trying to get node-lame to work under bordered Trying to get node-lame to work under node-red Oct 16, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants