Rantanen / node-opus

Opus bindings for Node.js
MIT License
79 stars 32 forks source link

Adding Raspberry Pi (1) support #2

Closed nfriedly closed 9 years ago

nfriedly commented 9 years ago

Hey, I followed the instructions in the readme to build the config.h file for my raspberry pi (and fleshed it out a bit): https://github.com/nfriedly/node-opus/commit/0ad226a74801f12e8f7b9b59686158c4866dde26

But, when I try to install from my repo, I get the following:

pi@raspberrypi ~/nodeplayer $ npm install https://github.com/nfriedly/node-opus
npm ERR! Linux 3.18.12+
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "https://github.com/nfriedly/node-opus"
npm ERR! node v0.12.2
npm ERR! npm  v2.7.4
npm ERR! code EBADPLATFORM

npm ERR! notsup Unsupported
npm ERR! notsup Not compatible with your operating system or architecture: node-opus@0.1.2
npm ERR! notsup Valid OS:    linux
npm ERR! notsup Valid Arch:  x64
npm ERR! notsup Actual OS:   linux
npm ERR! notsup Actual Arch: arm

Presumably one of the .gyp files needs to be updated, but I'm not sure which / how. Can you give me any pointers there?

nfriedly commented 9 years ago

Actually, I poked around a bit more and realized that was a package.json thing. But now I have the next issue:

-
> node-opus@0.1.2 install /home/pi/nodeplayer/node_modules/node-opus
> node-gyp rebuild

make: Entering directory '/home/pi/nodeplayer/node_modules/node-opus/build'
make: *** No rule to make target 'Release/obj.target/libopus/deps/opus/src/opus.o', needed by 'Release/obj.target/deps/opus.a'.  Stop.
make: Leaving directory '/home/pi/nodeplayer/node_modules/node-opus/build'
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:269:23)
gyp ERR! stack     at ChildProcess.emit (events.js:110:17)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (child_process.js:1074:12)
gyp ERR! System Linux 3.18.12+
gyp ERR! command "node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /home/pi/nodeplayer/node_modules/node-opus
gyp ERR! node -v v0.12.2
gyp ERR! node-gyp -v v1.0.3
gyp ERR! not ok 
npm ERR! Linux 3.18.12+
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "https://github.com/nfriedly/node-opus"
npm ERR! node v0.12.2
npm ERR! npm  v2.7.4
npm ERR! code ELIFECYCLE

npm ERR! node-opus@0.1.2 install: `node-gyp rebuild`
npm ERR! Exit status 1

Any ideas there? (Sorry, I'm a complete noob at this stuff.)

Rantanen commented 9 years ago

Hm. No idea what would cause that (although I'm a bit unfamiliar with all the intricacies of gyp as well).

Can you try the following?

I'm guessing this doesn't actually help you, I just want to confirm that it's that binding.gyp that is causing the problem.

On my system (Linux x64) the output is along the lines of:

wace@jubjub:~/projects/node-opus/deps$ node-gyp rebuild
gyp info it worked if it ends with ok
gyp info using node-gyp@1.0.3
gyp info using node@0.12.2 | linux | x64
gyp info spawn python
gyp info spawn args [ '/home/wace/.nvm/versions/node/v0.12.2/lib/node_modules/node-gyp/gyp/gyp_main.py',
gyp info spawn args   'binding.gyp',
gyp info spawn args   '-f',
gyp info spawn args   'make',
gyp info spawn args   '-I',
gyp info spawn args   '/home/wace/projects/node-opus/deps/build/config.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/home/wace/.nvm/versions/node/v0.12.2/lib/node_modules/node-gyp/addon.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/home/wace/.node-gyp/0.12.2/common.gypi',
gyp info spawn args   '-Dlibrary=shared_library',
gyp info spawn args   '-Dvisibility=default',
gyp info spawn args   '-Dnode_root_dir=/home/wace/.node-gyp/0.12.2',
gyp info spawn args   '-Dmodule_root_dir=/home/wace/projects/node-opus/deps',
gyp info spawn args   '--depth=.',
gyp info spawn args   '--no-parallel',
gyp info spawn args   '--generator-output',
gyp info spawn args   'build',
gyp info spawn args   '-Goutput_dir=.' ]
gyp info spawn make
gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
make: Entering directory `/home/wace/projects/node-opus/deps/build'
  CC(target) Release/obj.target/libopus/opus/src/opus.o
  CC(target) Release/obj.target/libopus/opus/src/opus_decoder.o
  CC(target) Release/obj.target/libopus/opus/src/opus_encoder.o
  CC(target) Release/obj.target/libopus/opus/src/opus_multistream.o
...

I'll see if I can reproduce this on my Pi if I can figure out where I've put it and whether it has an OS installed.

nfriedly commented 9 years ago

Yep, just as you suspected:

pi@raspberrypi ~/node-opus/deps $ node-gyp rebuild
gyp info it worked if it ends with ok
gyp info using node-gyp@1.0.3
gyp info using node@0.12.2 | linux | arm
gyp info spawn python
gyp info spawn args [ '/usr/local/lib/node_modules/node-gyp/gyp/gyp_main.py',
gyp info spawn args   'binding.gyp',
gyp info spawn args   '-f',
gyp info spawn args   'make',
gyp info spawn args   '-I',
gyp info spawn args   '/home/pi/node-opus/deps/build/config.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/usr/local/lib/node_modules/node-gyp/addon.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/home/pi/.node-gyp/0.12.2/common.gypi',
gyp info spawn args   '-Dlibrary=shared_library',
gyp info spawn args   '-Dvisibility=default',
gyp info spawn args   '-Dnode_root_dir=/home/pi/.node-gyp/0.12.2',
gyp info spawn args   '-Dmodule_root_dir=/home/pi/node-opus/deps',
gyp info spawn args   '--depth=.',
gyp info spawn args   '--no-parallel',
gyp info spawn args   '--generator-output',
gyp info spawn args   'build',
gyp info spawn args   '-Goutput_dir=.' ]
gyp info spawn make
gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
make: Entering directory '/home/pi/node-opus/deps/build'
make: *** No rule to make target 'Release/obj.target/libopus/opus/src/opus.o', needed by 'Release/obj.target/opus.a'.  Stop.
make: Leaving directory '/home/pi/node-opus/deps/build'
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/local/lib/node_modules/node-gyp/lib/build.js:269:23)
gyp ERR! stack     at ChildProcess.emit (events.js:110:17)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (child_process.js:1074:12)
gyp ERR! System Linux 3.18.12+
gyp ERR! command "node" "/usr/local/bin/node-gyp" "rebuild"
gyp ERR! cwd /home/pi/node-opus/deps
gyp ERR! node -v v0.12.2
gyp ERR! node-gyp -v v1.0.3
gyp ERR! not ok 

I'm on a 256mb Pi 1 running the 2015-02-16 release of Raspbian (https://www.raspberrypi.org/downloads/) and running node.js binaries from http://conoroneill.net/node-v0122-for-arm-v6v7-including-raspberry-pi-raspberry-pi-2-and-odroid-c1

I'm specifically trying to get this chunk of code to work (only with the accept header switched to opus):

var fs = require('fs');
var watson = require('watson-developer-cloud');
var Speaker = require('speaker');
var wav = require('wav');

var reader = new wav.Reader();;

var text_to_speech = watson.text_to_speech({
  username: '0eaef628-d28e-4365-b0db-069046f37fef',
  password: 'Mm1DWPHFC7sq',
  version: 'v1'
});

var params = {
  text: 'Hello from IBM Watson',
  accept: 'audio/wav' // or audio/ogg; codec=opus
};

var stream = text_to_speech.synthesize(params)

reader.on('format', function(format) {
    console.log('format', format);
    reader.pipe(new Speaker(format)).on('error', function(err) {console.error(err.stack);});
});

stream.pipe(reader);

In wav mode, it plays, but it's super choppy (probably because I'm on a crappy slow DSL connection out in the countryside...). So, I'm thinking that opus will help, at least if I can get it to compile.

After that, I'll see if I can make a nice Stream implementation to make it easy to pipe a http response into node-opus and then from there into speaker (and wav if we need it). I'll send you another PR once I have that working well.

nfriedly commented 9 years ago

Just for kicks, I did the same steps on my macbook and it looks like the issue crops up there as well:

Nathans-MBP:player nfriedly$ npm install https://github.com/nfriedly/node-opus
-
> node-opus@0.1.2 install /Users/nfriedly/player/node_modules/node-opus
> node-gyp rebuild

make: *** No rule to make target `Release/obj.target/libopus/deps/opus/src/opus.o', needed by `Release/opus.a'.  Stop.
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:269:23)
gyp ERR! stack     at ChildProcess.emit (events.js:110:17)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (child_process.js:1074:12)
gyp ERR! System Darwin 14.3.0
gyp ERR! command "node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/nfriedly/player/node_modules/node-opus
gyp ERR! node -v v0.12.2
gyp ERR! node-gyp -v v1.0.3
gyp ERR! not ok 
npm ERR! Darwin 14.3.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "https://github.com/nfriedly/node-opus"
npm ERR! node v0.12.2
npm ERR! npm  v2.7.4
npm ERR! code ELIFECYCLE

npm ERR! node-opus@0.1.2 install: `node-gyp rebuild`
npm ERR! Exit status 1
Rantanen commented 9 years ago

Found my Rasp. Trying to set it up but might go until tomorrow.

However for your use case you also need to look at: https://github.com/TooTallNate/node-ogg

node-opus is pure opus implementation, what you are dealing with is opus stream in an ogg container (which is the usual case).

I believe node-ogg already has some streaming functionality in it though (although I never got the whole library working. I believe I had some issues getting that one to compile). If you're planning on making node-opus streaming, take a look at how node-ogg and node-vorbis work together, both of them are by TooTallNate and I believe he has some generic interface all of his codecs use to talk with their containers.

Rantanen commented 9 years ago

facepalm

npm doesn't support git submodules, which the opus source directory is.

.. so npm install node-opus results in completely empty deps/opus >.>

oops..

Didn't bother trying a clear install on my end as I know some other people on Linux x64 who've been working on this so I figured it must be working in the general case.

Sorry!

Rantanen commented 9 years ago

Fixed. At least I was able to install it from npm now.

nfriedly commented 9 years ago

Hah, I didn't even think of that. I'll try out the new version and also check out node-ogg

nfriedly commented 9 years ago

Beautiful, I can now install it on my Pi (so, presumably it will work). However, while the pi was compiling, I tested it on my mac as well, and it's choking when looking for the config.h file. Does it need an OS variable at https://github.com/Rantanen/node-opus/blob/master/deps/binding.gyp#L3 ?

Nathans-MBP:player nfriedly$ npm install https://github.com/nfriedly/node-opus
\
> node-opus@0.1.3 install /Users/nfriedly/player/node_modules/node-opus
> node-gyp rebuild

  CC(target) Release/obj.target/libopus/deps/opus/src/opus.o
../deps/opus/src/opus.c:29:10: fatal error: 'config.h' file not found
#include "config.h"
         ^
1 error generated.
make: *** [Release/obj.target/libopus/deps/opus/src/opus.o] Error 1
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:269:23)
gyp ERR! stack     at ChildProcess.emit (events.js:110:17)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (child_process.js:1074:12)
gyp ERR! System Darwin 14.3.0
gyp ERR! command "node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/nfriedly/player/node_modules/node-opus
gyp ERR! node -v v0.12.2
gyp ERR! node-gyp -v v1.0.3
gyp ERR! not ok 
npm ERR! Darwin 14.3.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "https://github.com/nfriedly/node-opus"
npm ERR! node v0.12.2
npm ERR! npm  v2.7.4
npm ERR! code ELIFECYCLE

npm ERR! node-opus@0.1.3 install: `node-gyp rebuild`
npm ERR! Exit status 1
Rantanen commented 9 years ago

There's no config.h for macs so you'll need to generate it just like you did for the Pi. I don't have mac myself so can't do it - but I'll welcome a pull request. Someone did this for the node-celt project of mine so you can see that for an example:

https://github.com/Rantanen/node-celt/tree/master/deps/config/celt-0.7.1 Rantanen/node-celt@2c9edd14cd5de05178fc51789ac6c810eb3c3886

(And no, I got no idea why there are both darwin and mac directories. I just merged the PR) :)

nfriedly commented 9 years ago

Right, I did generate it: https://github.com/nfriedly/node-opus/blob/master/deps/config/opus/darwin/x64/config.h

Although I only used the darwin dir... let me try copying it to a mac dir.

Rantanen commented 9 years ago

Unfortunately node-ogg has issues with Node 0.12: TooTallNate/node-ogg#7

Hopefully that PR gets merged in at some point. Until then you could try running your project with Node v0.10 which seems to support all of the following:

.. at least I was able to npm install all of those, although for speaker I had to use the npm_config_mpg123_backend=dummy option as my server doesn't have speakers configured.

nfriedly commented 9 years ago

Oh, thanks.

I figured out the mac/darwin thing: the package.json listing must be "darwin" but the config folder must be named "mac". So, PR incoming with that and my RPi config ;)

nfriedly commented 9 years ago

Hey I put together a stream wrapper for this lib and tried to use it with the ogg and speaker libraries. With node 0.10, I get audio out of my speakers that's about the right length, but utterly incomprehensible. (And, as you mentioned, it doesn't work at all on 0.12.)

It sounds the same whether I play from disk or stream, so I don't think bandwidth is the issue this time.

So, sorry to hijack a closed issue, but if you get a minute, I'd appreciate any thoughts you could offer: https://gist.github.com/nfriedly/c4549e76440d7e703d43