Created
November 22, 2016 13:50
-
-
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!"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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