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

Adding Node module for snowboy #52

Merged
merged 8 commits into from
Sep 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,7 @@ snowboydetect.py
/swig/Android/java/
/swig/Android/jniLibs/

/build
/node_modules
/lib/node/binding
/lib/node/index.js
23 changes: 23 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/lib/libsnowboy-detect.a
snowboy-detect-swig.cc
snowboydetect.py
.DS_Store

*.pyc
*.o
*.so

/examples/C++/*
/examples/Python/*

/swig/Android/*
/swig/Python/*

/build
/node_modules

/lib/node/*.ts
/lib/node/*.d.ts

.npmignore
.travis.yml
87 changes: 87 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
language: cpp

# Cache node dependencies
cache:
directories:
- node_modules

# Ubuntu 14.04 Trusty support
sudo: required
dist: trusty

addons:
apt:
sources:
# add PPAs with more up-to-date toolchains
- ubuntu-toolchain-r-test
- llvm-toolchain-precise-3.9
packages:
# install toolchains
- libmagic-dev
- libatlas-base-dev
- gcc-5
- g++-5
- clang-3.8

os:
- linux
- osx

env:
global:
- secure: i1H9nLTmwznGjZNrX2dYf8NmeMnHQRqZPErXenMe67zhI1NWZNd5Q4dkZKKMUUmZZa/aLPT9biYzeVsoxyX2zbbHl8cruVLqh67FwKdedf/m4quzn1U5MRznPFdzEb9LzyU6IKGJQYLDzCTlBpoZe8LQEIxwx/Fn7H5DxPXIQN2+YP4euDNdSdjr3PB3IaOf719gwmTbLnxpdUr2/u7ZUTu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Xpkyb5JokWBZ9GO6yRt2V4VgHamZ853xcDHyuj7X2YHPLgnCKcM5kIxxzQkEa/ZtyFjM2/XWkABwYLXQ8mdbXmSMUH8=
matrix:
- NODE_VERSION="4.0.0"
- NODE_VERSION="5.0.0"
- NODE_VERSION="6.0.0"

before_install:
# use the correct version of node
- rm -rf ~/.nvm/ && git clone --depth 1 https://github.com/creationix/nvm.git ~/.nvm
- source ~/.nvm/nvm.sh
- nvm install $NODE_VERSION
- nvm use $NODE_VERSION
# get commit message
- COMMIT_MESSAGE=$(git show -s --format=%B $TRAVIS_COMMIT | tr -d '\n')
# put local node-pre-gyp on PATH
- export PATH=./node_modules/.bin/:$PATH
# put global node-gyp on PATH
- npm install node-gyp -g
# install aws-sdk so it is available for publishing
- npm install aws-sdk
# figure out if we should publish or republish
- PUBLISH_BINARY=false
- REPUBLISH_BINARY=false
# if we are building a tag then publish
- if [[ $TRAVIS_BRANCH == `git describe --tags --always HEAD` ]]; then PUBLISH_BINARY=true; fi;
# or if we put [publish binary] in the commit message
- if test "${COMMIT_MESSAGE#*'[publish binary]'}" != "$COMMIT_MESSAGE"; then PUBLISH_BINARY=true; fi;
# alternativly we can [republish binary] which will replace any existing binary
- if test "${COMMIT_MESSAGE#*'[republish binary]'}" != "$COMMIT_MESSAGE"; then PUBLISH_BINARY=true && REPUBLISH_BINARY=true; fi;
install:
# ensure source install works
- npm install --build-from-source
# test our module
- node lib/node/index.js

before_script:
# if publishing, do it
- if [[ $REPUBLISH_BINARY == true ]]; then node-pre-gyp package unpublish; fi;
- if [[ $PUBLISH_BINARY == true ]]; then node-pre-gyp package publish; fi;
# cleanup
- node-pre-gyp clean
- node-gyp clean

script:
# if publishing, test installing from remote
- INSTALL_RESULT=0
- if [[ $PUBLISH_BINARY == true ]]; then INSTALL_RESULT=$(npm install --fallback-to-build=false > /dev/null)$? || true; fi;
# if install returned non zero (errored) then we first unpublish and then call false so travis will bail at this line
- if [[ $INSTALL_RESULT != 0 ]]; then echo "returned $INSTALL_RESULT";node-pre-gyp unpublish;false; fi
# If success then we arrive here so lets clean up
- node-pre-gyp clean

after_success:
# if success then query and display all published binaries
- node-pre-gyp info
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ by [KITT.AI](http://kitt.ai).
[Full Documentation](http://docs.kitt.ai/snowboy)


Version: 1.0.4 (7/13/2016)
Version: 1.1.0 (9/14/2016)

Snowboy is a customizable hotword detection engine for you to create your own
hotword like "OK Google" or "Alexa". It is powered by deep neural networks and
Expand Down Expand Up @@ -39,6 +39,15 @@ pull request!
If you want support on other hardware/OS, please send your request to
[[email protected]](mailto:snowboy.kitt.ai)

## Precompiled node module

Snowboy is available in the form of a native node module precompiled for: 64 bit Ubuntu, MacOS X, and the Raspberry Pi (Raspbian 8.0+).
For quick installation run:

npm install --save snowboy

For sample usage see the `examples/Node` folder.

## Precompiled Binaries with Python Demo
* 64 bit Ubuntu [12.04](https://s3-us-west-2.amazonaws.com/snowboy/snowboy-releases/ubuntu1204-x86_64-1.0.4.tar.bz2)
/ [14.04](https://s3-us-west-2.amazonaws.com/snowboy/snowboy-releases/ubuntu1404-x86_64-1.0.4.tar.bz2)
Expand Down Expand Up @@ -82,6 +91,15 @@ Make sure that you can record audio with your microphone:

If you need extra setup on your audio (especially on a Raspberry Pi), please see the [full documentation](http://docs.kitt.ai/snowboy).

## Compile a Node addon
Compiling a node addon for Linux and the Raspberry Pi requires the installation of the following dependencies:

sudo apt-get install libmagic-dev libatlas-base-dev

Then to compile the addon run the following from the root of the snowboy repository:

node-pre-gyp clean configure build

## Compile a Python Wrapper

cd swig/Python
Expand Down Expand Up @@ -169,6 +187,10 @@ See [Full Documentation](http://docs.kitt.ai/snowboy).

## Change Log

**v1.1.0, 9/14/2016**

* Added library for Node.

**v1.0.4, 7/13/2016**

* Updated universal `snowboy.umdl` model to make it more robust.
Expand Down
69 changes: 69 additions & 0 deletions binding.gyp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
'targets': [{
'target_name': 'snowboy',
'sources': [
'swig/Node/snowboy.cc'
],
'conditions': [
['OS=="mac"', {
'link_settings': {
'libraries': [
'<(module_root_dir)/lib/osx/libsnowboy-detect.a',
]
}
}],
['OS=="linux" and target_arch=="x64"', {
'link_settings': {
'libraries': [
'<(module_root_dir)/lib/ubuntu64/libsnowboy-detect.a',
]
}
}],
['OS=="linux" and target_arch=="arm"', {
'link_settings': {
'libraries': [
'<(module_root_dir)/lib/rpi/libsnowboy-detect.a',
]
}
}]
],
'cflags': [
'-std=c++11',
'-fexceptions',
'-Wall',
'-D_GLIBCXX_USE_CXX11_ABI=0'
],
'cflags!': [
'-fno-exceptions'
],
'cflags_cc!': [
'-fno-exceptions'
],
'include_dirs': [
"<!(node -e \"require('nan')\")",
"<!(pwd)/include"
],
'libraries': [
'-lcblas'
],
'xcode_settings': {
'MACOSX_DEPLOYMENT_TARGET': '10.11',
"GCC_ENABLE_CPP_EXCEPTIONS": "YES",
'OTHER_CFLAGS': [
'-std=c++11',
'-stdlib=libc++'
]
}
},
{
"target_name": "action_after_build",
"type": "none",
"dependencies": [ "<(module_name)" ],
"copies": [
{
"files": [ "<(PRODUCT_DIR)/<(module_name).node" ],
"destination": "<(module_path)"
}
]
}]
}
38 changes: 38 additions & 0 deletions examples/Node/file.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const fs = require('fs');
const wav = require('wav');
const {Detector, Models} = require('../../');

const models = new Models();

models.add({
file: 'resources/snowboy.umdl',
sensitivity: '0.5',
hotwords : 'snowboy'
});

const detector = new Detector({
resource: "resources/common.res",
models: models,
audioGain: 1.0
});

detector.on('silence', function () {
console.log('silence');
});

detector.on('sound', function () {
console.log('sound');
});

detector.on('error', function () {
console.log('error');
});

detector.on('hotword', function (index, hotword) {
console.log('hotword', index, hotword);
});

const file = fs.createReadStream('resources/snowboy.wav');
const reader = new wav.Reader();

file.pipe(reader).pipe(detector);
39 changes: 39 additions & 0 deletions examples/Node/microphone.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const record = require('node-record-lpcm16');
const {Detector, Models} = require('../../');

const models = new Models();

models.add({
file: 'resources/snowboy.umdl',
sensitivity: '0.5',
hotwords : 'snowboy'
});

const detector = new Detector({
resource: "resources/common.res",
models: models,
audioGain: 2.0
});

detector.on('silence', function () {
console.log('silence');
});

detector.on('sound', function () {
console.log('sound');
});

detector.on('error', function () {
console.log('error');
});

detector.on('hotword', function (index, hotword) {
console.log('hotword', index, hotword);
});

const mic = record.start({
threshold: 0,
verbose: true
});

mic.pipe(detector);
1 change: 1 addition & 0 deletions examples/Node/resources
13 changes: 13 additions & 0 deletions lib/node/SnowboyDetectNative.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
interface SnowboyDetectNativeInterface {
new (resource: string, models: string): SnowboyDetectNativeInterface;
Reset(): boolean;
RunDetection(audioData: Buffer): number;
SetSensitivity(sensitivity: string): void;
GetSensitivity(): string;
SetAudioGain(audioGain: number): void;
UpdateModel(): void;
NumHotwords(): number;
SampleRate(): number;
NumChannels(): number;
BitsPerSample(): number;
}
Loading