UNPKG

sonus

Version:

Open source cross platform decentralized always-on speech recognition framework

32 lines (23 loc) 1 kB
'use strict' const ROOT_DIR = __dirname + '/../' const Sonus = require(ROOT_DIR + 'index.js') //require('sonus') const speech = require('@google-cloud/speech') const client = new speech.SpeechClient({ projectId: 'streaming-speech-sample', keyFilename: ROOT_DIR + 'keyfile.json' }) const hotwords = [{ file: ROOT_DIR + 'resources/sonus.pmdl', hotword: 'sonus' }] const language = "en-US" //recordProgram can also be 'arecord' which works much better on the Pi and low power devices const sonus = Sonus.init({ hotwords, language: language, recordProgram: "rec" }, client) Sonus.start(sonus) console.log('Say "' + hotwords[0].hotword + '"...') sonus.on('hotword', (index, keyword) => console.log("!" + keyword)) sonus.on('partial-result', result => console.log("Partial", result)) sonus.on('error', error => console.log('error', error)) sonus.on('final-result', result => { console.log("Final", result) if (result.includes("stop")) { Sonus.stop() } })