Kitt-AI / snowboy

Future versions with model training module will be maintained through a forked version here: https://github.com/seasalt-ai/snowboy
Other
3.03k stars 994 forks source link

Building electron on Raspian - Raspberry Pi 3 #187

Open dolanmiu opened 7 years ago

dolanmiu commented 7 years ago

I get this error, it seems like it cannot build electron binaries:

WARNING! Could not load config file. Starting with default configuration. 
Error found: 
Error: Cannot find module '/home/pi/MagicMirror/modules/MMM-awesome-alexa/node_modules/snowboy/lib/node/binding/Release/electron-v1.6-linux-arm/snowboy.node

I am using node 6.10.3 Raspian - Raspberry Pi 3

@bogdan1133

chenguoguo commented 7 years ago

Did you try compiling it from our github repo? Or did you use the pre-compiled library for node?

dolanmiu commented 7 years ago

I used the pre-compiled lib for node, I didn't do any compiling myself, only npm install

and npm did all the magic and hard work

chenguoguo commented 7 years ago

Could you checkout our repository and try to compile it? See here: https://github.com/Kitt-AI/snowboy#compile-a-node-addon

bohdanabadi commented 7 years ago

It boots now, one problem after starting the program on the terminal it stops recording immediately. It shows something like this : End Recording: 106.121ms

chenguoguo commented 7 years ago

@bogdanabadi see here, https://github.com/Kitt-AI/snowboy/issues/176, probably your mic is not properly set up.

bohdanabadi commented 7 years ago

In that thread their microphone wasn't working, so running command like rec for them throws an error unlike me which records through the hdwebcam 3000. I have followed http://docs.kitt.ai/snowboy/#access-microphone guide and still not working and stops recording immediately.

Just to make things clear what I am trying to achieve, I am using MagicMirror2 that is basically electron with widgets and I want to integrate alexa as an extra module. When electron boots up it ask for the mic. Does that cause an error because electron requests the mic and snowboy via terminal or is it not relevant.

PS: On a Mac it works just fine. @dolanmiu

chenguoguo commented 7 years ago

I'm also including @evancohen as he might have some insights

bohdanabadi commented 7 years ago

I found something interesting, the MagicMirro2 (Electron) occupying the mic and thus snowboy can't detect the mic. When disabling the mic request in electron, snowboy can access the mic and detect the hotword. Do you recommend releasing the mic from snowboy as soon as a hotword is detected and passing to electron, or send the audio file from snowboy without releasing the mic. Which is best practice ?

PS: Someone had an issue and somehow fixed it https://github.com/gillesdemey/node-record-lpcm16/issues/33. But how come it causes no issue on my mac ?

chenguoguo commented 7 years ago

I see, ideally you would share the audio capturing for Snowboy and whatever other programs using audio.

dolanmiu commented 7 years ago

I see, ideally you would share the audio capturing for Snowboy and whatever other programs using audio.

Do you mean do the recording in one place, and then pass the recorded .wav file to places which need the recorded file?

chenguoguo commented 7 years ago

Yes, but you don't necessarily have to save to the audio to the file. You can "route" the audio to either Snowboy or some other applications that are using the audio. Snowboy supports audio streaming, which means you can send the audio to Snowboy chunk by chunk.

evancohen commented 7 years ago

When you try to install the precompiled snowboy module you're active runtime is ~arm - but when you try to include it inside your electron project it looks for the electron-v1.6-linux-arm binary (when only the arm binary exists).

The best way to fix this would be to recompile for electron/ARM or to set the correct environmental variables before running npm install. You may want to take a look at my sonus-electron-boilerplate as a starting point; The key in this case being .npmrc.

bohdanabadi commented 7 years ago

@chenguoguo @evancohen Thank you for the reply. But @evancohen can you elaborate a bit more ? So when you say only the arm binary exists, what is it unable to do ? Share the mic between Snowboy and electron ?

evancohen commented 7 years ago

Electron packages it's own versions of Node and V8, separate from what you have installed locally. When you are using a prebuilt binary within the electron runtime it looks for the binary associated with electron (in your case electron-v1.6-linux-arm), not the binary that was installed when you ran npm install, which is determined by the version of node that you have installed locally.

Here's the relevant Electron documentation: Using Native Node Modules

datapimp commented 7 years ago

have you tried forking in the electron process and using process.env.ELECTRON_RUN_AS_NODE

https://electron.atom.io/docs/api/environment-variables/

evancohen commented 7 years ago

@datapimp I'd never actually seen that, thanks for pointing it out! You can also use spawn('node', ...) to crate a child process.

That said, neither of these options would work if you're trying to package and distribute your app, because that would require the end user to have the same version of node installed on their machine that you've got. I suppose you could also bundle binaries for every version of node out there right now, but that would break if they upgraded :/

datapimp commented 7 years ago

Electron ships with node already, so when you do that it uses that node but doesn't provide any of the electron core modules to your runtime. You still need to bundle any dependencies and handle native deps, but nothing electron builder won't make painless

evancohen commented 7 years ago

Ooh, I totally see what you are saying! Electron builder would download/build the binaries for the bundled version of node, similar to what I was saying before - minus the runtime. Totally going to give that a shot over the weekend.

Thanks for the pro-tip 👍