-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
86 lines (66 loc) · 2.01 KB
/
index.js
File metadata and controls
86 lines (66 loc) · 2.01 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
'use strict'
const Sonus = require('sonus');
const lights = require('./Components/Lights');
const util = require('./Utilities');
const settings = require('./Settings');
const speech = require('@google-cloud/speech')({
projectId: settings.google.projectId,
keyFilename: settings.keyFileName
});
const hotwords = [{ file: './jarvis.pmdl', hotword: 'jarvis' }];
const language = "en-US";
const sonus = Sonus.init({ hotwords, language }, speech);
const default_room = 'office';
try {
Sonus.trigger(sonus, 1)
} catch (e) {
console.log('Triggering Sonus before starting it will throw the following exception:', e)
}
Sonus.start(sonus)
sonus.on('hotword', (index, keyword) => {
console.log("Index----->" + index);
console.log("Keyword--->" + keyword);
}
);
sonus.on('partial-result', result => console.log("Partial---->", result))
sonus.on('error', (error) => console.log(error))
sonus.on('final-result', result => {
console.log("Final--->", result)
/*
if (result.includes("stop")) {
Sonus.stop()
}
*/
/* HANDLE HUES LIGHTS */
if (result.includes('lights') || result.includes('light') || result.includes('mood')) {
let room;
// Determine room
if (result.includes('in the')) {
room = result.substring(result.indexOf('in the ') + 7, result.length).toLowerCase();
}
room = (room) ? room : default_room;
if (result.includes('mood to')) {
console.log('mood');
const scene = result.substring(result.indexOf('mood to') + 7, result.length);
lights.scene(room, scene);
}
if (result.includes('on')) {
console.log('turn on');
lights.on(room);
}
if (result.includes('off')) {
lights.off(room);
}
if (result.includes('brighten') || result.includes('brighter')) {
lights.brighten(room);
}
if (result.includes('dim') || result.includes('dimmer')) {
lights.dim(room);
}
}
})
try {
Sonus.trigger(sonus, 2)
} catch (e) {
console.log('Triggering Sonus with an invalid index will throw the following error:', e)
}