Skip to content

Instantly share code, notes, and snippets.

@arm5077
Created November 22, 2016 13:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arm5077/ef498a7e31e4d799431d5ce734898907 to your computer and use it in GitHub Desktop.
Save arm5077/ef498a7e31e4d799431d5ce734898907 to your computer and use it in GitHub Desktop.
A script for the Raspberry Pi that turns on a Powerswitch when the user says "Lumos!"
const record = require('node-record-lpcm16');
const {Detector, Models} = require('./node_modules/snowboy/');
const Gpio = require('onoff').Gpio;
// Set up control of the pin that toggles the Powerswitch
power = new Gpio(14, 'out');
var on = false;
// Turn the power off by default
power.writeSync(0);
const models = new Models();
// Add "Lumos!" hotword
models.add({
file: 'Lumos.pmdl',
sensitivity: '0.5',
hotwords : 'lumos'
});
// Add "Nox!" hotword
models.add({
file: 'Nox.pmdl',
sensitivity: '0.5',
hotwords : 'nox'
});
const detector = new Detector({
resource: "./node_modules/snowboy/resources/common.res",
models: models,
audioGain: 2.0
});
detector.on('silence', function () {
});
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 == 'lumos')
// Turn on power to lights
power.writeSync(1);
else if(hotword == 'nox')
// Turn off power
power.writeSync(0);
});
const mic = record.start({
threshold: 0,
verbose: true
});
mic.pipe(detector);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment