-
Notifications
You must be signed in to change notification settings - Fork 79
/
Copy pathannyang-example.js
39 lines (33 loc) · 1.14 KB
/
annyang-example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
'use strict'
const ROOT_DIR = __dirname + '/../'
const Sonus = require(ROOT_DIR + 'index.js')
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"
const sonus = Sonus.init({ hotwords, language: language }, client)
const commands = {
'hello': function () {
console.log('You will obey');
},
'(give me) :flavor ice cream': function (flavor) {
console.log('Fetching some ' + flavor + ' ice ceam for you sr')
},
'turn (the)(lights) :state (the)(lights)': function (state) {
console.log('Turning the lights', (state == 'on') ? state : 'off')
}
}
Sonus.annyang.addCommands(commands)
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('final-result', result => {
console.log("Final", result)
if (result.includes("stop")) {
Sonus.stop()
}
})