-
Notifications
You must be signed in to change notification settings - Fork 3
/
jacss_speach.js
63 lines (59 loc) · 2.21 KB
/
jacss_speach.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
var jacss_speach = function () {
// do context switch if necessary (for future to support several 'presentations':
if (this == window) {
jacss_speach.call(jacss_speach);
return;
}
var config = { speach: "#speach", speach_verbs : { next: "next step", prev: "previous step"} };
//var config = { server: '127.0.0.1:8088', name: window.location.host + window.location.pathname, share: "#share", simulate: true };
for (var n in config) {
//noinspection JSUnfilteredForInLoop
if (Object.prototype.hasOwnProperty.call(jacss.config, n)) { //noinspection JSUnfilteredForInLoop
config[n] = jacss.config[n];
}
}
if (!window.webkitSpeechRecognition) return;
var btn = document.querySelector(config.speach);
btn.classList.add('visible');
var recognizing;
var recognition = new window.webkitSpeechRecognition();
recognition.continuous = true;
recognition.interimResults = false;
reset();
recognition.onend = reset;
recognition.onresult = function (event) {
console.log('result', event);
for (var i = resultIndex; i < event.results.length; ++i) {
if (event.results.final) {
//textarea.value += event.results[i][0].transcript;
console.log(event.results[i][0].transcript);
if (event.results[i][0].transcript == config.speach_verbs.next)
jacss.next();
else if (event.results[i][0].transcript == config.speach_verbs.next)
jacss.previous();
}
}
}
recognition.onerror = function(event) {
console.log("Error: ", event);
}
function reset() {
console.log("reseting...");
recognizing = false;
btn.classList.remove('active');
}
function toggleStartStop() {
if (recognizing) {
recognition.stop();
reset();
} else {
recognition.lang = 'ru_RU';
recognition.start();
recognizing = true;
btn.classList.add('active');
}
console.log(recognizing);
}
btn.addEventListener('click', toggleStartStop);
};
window.addEventListener("load", jacss_speach, false);