This repository has been archived by the owner on Apr 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bin.js
executable file
·221 lines (198 loc) · 6.38 KB
/
bin.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
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
// set start vars
var speechsynthesisstart = true;
var speechrecognitionstart = true;
var visionstart = true;
var sfxstart = true;
var colorstart = true;
var bootstrapstart = true;
var verbose = false;
var configfilefound = false;
// process config.json file
loadconfig();
// process command line arguments
argumental();
// include screenwipe module
const screenhist = require('./screenhist.js');
screenhist.wipe();
// include colored responses module
const response = require('./response.js');
if (!colorstart) {
response.unsetcolors('silent');
}
if (verbose) {
response.setverbose('silent');
}
// include help function module
const help = require('./help.js');
// include prompt module
const prompt = require('./prompt.js');
// include sfx module
const sfx = require('./sfx.js');
// include voice synthesis module
const voice = require('./voice.js');
// include speech recognition module
const hearing = require('./hearing.js');
// include vision module
const vision = require('./vision.js');
// include bootstrap module
const bootstrap = require('./bootstrap.js');
// start prompt
prompt.start();
prompt.setCompletion(['help', 'add', 'edit', 'list', 'start', 'stop', 'listening', 'hearing', 'voice', 'voices', 'talking', 'silence', 'quiet', 'vision', 'watching', 'verbose', 'colors', 'command', 'execution', 'parsing', 'sound', 'effects', 'sfx']);
if (configfilefound) {
response.conlog('prompt', 'loading settings from configuration file (./config.json)', 'status');
} else {
response.conlog('prompt', 'no configuration file found (./config.json)', 'status');
}
if (verbose) {
response.conlog('prompt', 'verbose mode activated', 'status');
}
if (colorstart) {
response.conlog('response', 'colored responses activated', 'status');
} else {
response.conlog('response', 'colored responses not activated: --no-colors flag', 'status');
}
if (typeof help !== undefined) {
response.conlog('help', 'helper function activated', 'status');
}
// start voice
if (sfxstart) {
sfx.start();
} else {
response.conlog('sfx', 'sound effects not activated: --no-sound-effects flag', 'status');
}
// start voice
if (speechsynthesisstart) {
voice.start();
} else {
response.conlog('voice', 'speech synthesis not activated: --no-voice flag', 'status');
}
// start speech recognition, keyword: sara
if (speechrecognitionstart) {
hearing.listen();
} else {
response.conlog('hearing', 'speech recognition not activated: --no-speech-recognition flag', 'status');
}
// start vision
if (visionstart) {
vision.start();
} else {
response.conlog('vision', 'vision not activated: --no-vision flag', 'status');
}
// start bootstrap
if (bootstrapstart) {
bootstrap.start();
} else {
response.conlog('bootstrap', 'bootstrap not activated: --no-bootstrap flag', 'status');
}
sfx.output('startup');
/*
function myFunc() {
prompt.write('This is a test');
}
setTimeout(myFunc, 5000);
*/
function loadconfig() {
const fs = require('fs')
const path = './config.json'
try {
if (fs.existsSync(path)) {
configfilefound = true;
var configfile = require('./config.json');
if (configfile['speech synthesis'] == true) {
speechsynthesisstart = true;
} else {
speechsynthesisstart = false;
}
if (configfile['speech recognition'] == true) {
speechrecognitionstart = true;
} else {
speechrecognitionstart = false;
}
if (configfile['vision'] == true) {
visionstart = true;
} else {
visionstart = false;
}
if (configfile['sound effects'] == true) {
sfxstart = true;
} else {
sfxstart = false;
}
if (configfile['colors'] == true) {
colorstart = true;
} else {
colorstart = false;
}
if (configfile['bootstrap'] == true) {
bootstrapstart = true;
} else {
bootstrapstart = false;
}
if (configfile['verbose'] == true) {
verbose = true;
} else {
verbose = false;
}
}
} catch(err) {
configfilefound = false;
}
}
function argumental() {
process.argv.forEach(function (val, index, array) {
val = val.trim();
if (val.toLowerCase() == '--verbose' || val == '-v') {
verbose = true;
}
if (val.toLowerCase() == '--no-bootstrap' || val == '-nb') {
bootstrapstart = false;
}
if (val.toLowerCase() == '--no-colors' || val == '-nc') {
colorstart = false;
}
if (val.toLowerCase() == '--no-sound-effects' || val == '-nse') {
sfxstart = false;
}
if (val.toLowerCase() == '--no-voice' || val == '-nv') {
speechsynthesisstart = false;
}
if (val.toLowerCase() == '--no-vision' || val == '-nV') {
visionstart = false;
}
if (val.toLowerCase() == '--no-speech-recognition' || val == '-nsr') {
speechrecognitionstart = false;
}
if (val.toLowerCase() == '--help' || val == '-h') {
console.log('(--help)');
console.log('');
console.log('Usage: sara [OPTIONS]');
console.log('');
console.log('arguments:');
console.log('\t-h, --help\tDisplay this help and exits');
console.log('\t-nb, --no-bootstrap\tDo not activate bootstrap plugins on start');
console.log('\t-nc, --no-colors\tDo not activate colored responses on start');
console.log('\t-nse, --no-sound-effects\tDo not activate sound effects on start');
console.log('\t-nsr, --no-speech-recognition\tDo not activate speech recognition on start');
console.log('\t-nv, --no-voice\tDo not activate speech synthesis on start');
console.log('\t-nV, --no-vision\tDo not activate webcam on start');
console.log('\t-v, --verbose\tDisplay additional information, noisy (debug data)');
console.log('\t-V, --version\tDisplay version number and exits');
console.log('');
console.log('config file:');
console.log('\tThe file config.json allow you to set the above arguments as default');
console.log('\t\Arguments override config.json settings');
console.log('\t\'verbose: false\' in config.json AND --verbose will turn ON verbose');
console.log('');
console.log('Internal help function is available by typing \'help\' in SARAs prompt');
process.exit();
}
if (val.toLowerCase() == '--version' || val == '-V') {
const { version } = require('./package.json');
console.log('(--version)');
console.log('');
console.log(version);
process.exit();
}
});
}