RedKenrok / node-hotworddetector

Hotword detector wrapper of Snowboy by Kitt.ai with microphone functionality build-in.
MIT License
12 stars 2 forks source link

node-hotworddetector compatible with latest snowboy 1.3.1? #1

Closed b-g closed 6 years ago

b-g commented 6 years ago

Hi @RedKenrok, many thanks for this module! Just ... I have trouble getting it to run :)

// node v8.4.0
// macOS 10.12.6

const HotwordDetector = require('node-hotworddetector');

const modelData = [{
    file: './node_modules/snowboy/resources/models/snowboy.umdl',
    hotwords : 'snowboy'
  }];
const detectorData = {
  resource: './node_modules/snowboy/resources/common.res'
};
const recorderData = {};
const logger = {
  log: console.log,
  warn: console.warn
};

let hotwordDetector = new HotwordDetector(modelData, detectorData, recorderData, logger);

hotwordDetector.on('error', function(error) {
  console.error('hotwordDetector: ' + error);
});

hotwordDetector.on('hotword', function(index, hotword, buffer) {
  console.log('hotwordDetector: Hotword detected: ' + hotword);
});

hotwordDetector.start();

result is:

$ node example.js 
AudioRecorder command: rec -V0 -q -L -r 16000 -c 1 -e signed-integer -b 16 -t wav - silence 1 0.1 0% 1 2 0%
HotwordDetector initialized.
ERROR (Init():pipeline-detect.cc:143) PipelineDetect: no model detected! You have to provide at least one personal or one universal model by calling SetModel().
libc++abi.dylib: terminating with uncaught exception of type std::runtime_error
Abort trap: 6

SoX is installed and apparently works, tested with $ rec.

It seems that the snowboy modules has changed, e.g. models have their own folder now (you might want to change that path in your README.md too). Could you double check whether your module is still compatible with the latest snowboy v1.3.1? It seems your module assumes snowboy v1.2.0 https://github.com/RedKenrok/node-hotworddetector/blob/master/package.json#L24

screen shot 2018-06-25 at 13 16 13

Here is also my example as a node project. hotword-example.zip

RedKenrok commented 6 years ago

I'm looking into it, and will probably update the module as a whole at the same time.

RedKenrok commented 6 years ago

I can confirm that I have the same error as well. Meanwhile I also found someone with the same issue in the snowboy repository: Kitt-AI/snowboy#441. I would recommend using version 1.2.0 for now, or do you have any problems with that version as well?

I have added a develop branch where you can see a version of the module which uses Snowboy 1.3.1. As expected it does not work on elementary OS 0.4.1 Loki (64-bit) running node version 8.9.4.

b-g commented 6 years ago

Thanks for the confirmation and tips! But still no luck :(

I've installed npm install snowboy@1.2.0 and adjusted the resources paths to:

// node v8.4.0
// macOS 10.12.6

const HotwordDetector = require('node-hotworddetector');

const modelData = [{
    file: './node_modules/snowboy/resources/snowboy.umdl',
    hotwords : 'snowboy'
  }];
const detectorData = {
  resource: './node_modules/snowboy/resources/common.res'
};
const recorderData = {};
const logger = {
  log: console.log,
  warn: console.warn
};

let hotwordDetector = new HotwordDetector(modelData, detectorData, recorderData, logger);

hotwordDetector.on('error', function(error) {
  console.error('hotwordDetector: ' + error);
});

hotwordDetector.on('hotword', function(index, hotword, buffer) {
  console.log('hotwordDetector: Hotword detected: ' + hotword);
});

hotwordDetector.start();

Result is:

$ node example.js 
AudioRecorder command: rec -V0 -q -L -r 16000 -c 1 -e signed-integer -b 16 -t wav - silence 1 0.1 0% 1 2 0%
HotwordDetector initialized.
ERROR (Init():pipeline-detect.cc:136) PipelineDetect: no model detected! You have to provide at least one personal or one universal model by calling SetModel().
/Users/bene/Desktop/hotword-example/node_modules/snowboy/lib/node/index.js:64
        this.nativeInstance = new SnowboyDetectNative(options.resource, options.models.modelString);
                              ^

Error: ERROR (Init():pipeline-detect.cc:136) PipelineDetect: no model detected! You have to provide at least one personal or one universal model by calling SetModel().

[stack trace: ]
0   snowboy.node                        0x0000000103e41ffe _ZN7snowboy13GetStackTraceEv + 94
1   snowboy.node                        0x0000000103e42cd5 _ZN7snowboy13SnowboyLogMsgD2Ev + 421
2   snowboy.node                        0x0000000103e3a2f4 _ZN7snowboy14PipelineDetect4InitEv + 660
3   snowboy.node                        0x0000000103e575f4 _ZN7snowboy13SnowboyDetectC2ERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEES9_ + 148
4   snowboy.node                        0x0000000103e012dd _ZN13SnowboyDetectC2ERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEES8_ + 77
.
.
.
6   snowboy.node                        0x0000000103e02daa _ZN3Nan3impL23FunctionCallbackWrapperERKN2v820FunctionCallbackInfoINS1_5ValueEEE + 136
7   node                                0x0000000100216432 _ZN2v88internal25FunctionCallbackArguments4CallEPFvRKNS_20FunctionCallbackInfoINS_5ValueEEEE + 466
8   node                                0x000000010027792c _ZN2v88internal12_GLOBAL__N_119HandleApiCallHelperILb1EEENS0_11MaybeHandleINS0_6ObjectEEEPNS0_7IsolateENS0_6HandleINS0_10HeapObjectEEESA_NS8_INS0_20FunctionTemplateInfoEEENS8_IS4_EENS0_16BuiltinArgumentsE + 572
9   node                                0x0000000100277338 _ZN2v88internalL26Builtin_Impl_HandleApiCallENS0_16BuiltinArgumentsEPNS0_7IsolateE + 232
10  ???                                 0x00003666177840dd 0x0 + 59812108320989

    at new SnowboyDetect (/Users/bene/Desktop/hotword-example/node_modules/snowboy/lib/node/index.js:64:31)
    at setupDetector (/Users/bene/Desktop/hotword-example/node_modules/node-hotworddetector/index.js:37:13)
    at HotwordDetector.start (/Users/bene/Desktop/hotword-example/node_modules/node-hotworddetector/index.js:111:3)
    at Object.<anonymous> (/Users/bene/Desktop/hotword-example/example.js:29:17)
    at Module._compile (module.js:573:30)
    at Object.Module._extensions..js (module.js:584:10)
    at Module.load (module.js:507:32)
    at tryModuleLoad (module.js:470:12)
    at Function.Module._load (module.js:462:3)
    at Function.Module.runMain (module.js:609:10)
RedKenrok commented 6 years ago

My apologies, this seems to have been my mistake. I had updated the constructor, but seem to have forgotten to update the documentation properly.

Therefore try updating the libarary to version 1.2.0 and have a look at the constructor section of the README.md as well as the new example script. (Essentially switching the modelData and detectorData around in the constructor should fix it.)

b-g commented 6 years ago

:) Thanks!

Ok. Works almost now ... but still people won't be able to run your module as they will get v1.3.1 installed, where the models path has changed.

Hence I think you should make the dependency in package.json as specific as possible "snowboy": "^1.2.0" vs. "snowboy": "1.2.0". I would also recommend to update to "snowboy": "1.3.1" and to adjust the modelData path to the the folder ./node_modules/snowboy/resources/models/snowboy.umdl (note the new folder "models").

Here is my example working with snowboy v1.3.1:

const HotwordDetector = require('node-hotworddetector');

const detectorData = {
  resource: './node_modules/snowboy/resources/common.res'
};
const modelData = [{
    file: './node_modules/snowboy/resources/models/snowboy.umdl',
    hotwords : 'snowboy'
  }];

let hotwordDetector = new HotwordDetector(detectorData, modelData, {audioGain: 2}, console);

hotwordDetector.on('error', function(error) {
  console.error('hotwordDetector: ' + error);
});

hotwordDetector.on('hotword', function(index, hotword, buffer) {
  console.log('hotwordDetector: Hotword detected: ' + hotword);
});

hotwordDetector.start();
RedKenrok commented 6 years ago

Do you run npm install or npm install --save it is always recommend to use the latter as it installs the explicit versions mentioned in the package-lock.json. I'll patch it later today so the package.json reads "snowboy": "1.2.x"instead, this should resolve any issue.

I already have a version of this package that uses snowboy version 1.3.1, but unfortunately due to an issue in the snowboy package it isn't working. When that is resolved I'll be able to update this package as well.

RedKenrok commented 6 years ago

I have updated it so now it should grab version 1.2.0 instead.

b-g commented 6 years ago

Hi @RedKenrok,

npm install --save

Wow, wasn't aware of this. Thanks for the hint. Just I honestly think that a lot of "creative coders" like myself have never heard of this :). But I can confirm that with your new node-hotworddetector v1.2.1. The example works out of the box. Yay! Many thanks for this!

I already have a version of this package that uses snowboy version 1.3.1, but unfortunately due to an issue in the snowboy package it isn't working. When that is resolved I'll be able to update this package as well.

Hmm ... snowboy version 1.3.1 worked my machine. I just had to adjust the new models resources path.

Will close this issue.