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.07k stars 998 forks source link

Stop detection when hotword is found in Node #107

Closed tbass134 closed 7 years ago

tbass134 commented 7 years ago

Forgive me if this a simple answer, but I'm looking to find a way to stop the detection service after a hotword is detected.

In the python examples using detector.terminate() terminates the service. However, I don't see a way to do the same in Node.js

Here is my JS implementation so far.

const record = require('node-record-lpcm16');

const snowboy = require('snowboy');
const Detector = snowboy.Detector;
const Models = snowboy.Models;

const models = new Models();

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

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

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);
  if (hotword == 'vonage') {
      console.log('yes'); 
  } else if (hotword == 'take_a_message') {
      console.log('take a message');
      //stop detector service here

  }
});

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

mic.pipe(detector);
//console.log(snowboydecoder);
chenguoguo commented 7 years ago

You can use a combination of mic.pause(), mic.resume() or record.stop()

tbass134 commented 7 years ago

awesome thank you!

evancohen commented 7 years ago

@tbass134 for a complete implementation with streaming check out https://github.com/evancohen/sonus

tbass134 commented 7 years ago

thanks @evancohen i'll take a look