-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
54 lines (44 loc) · 1.4 KB
/
app.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
if(typeof(localStorage['isTired']) == 'undefined') localStorage['isTired'] = 1;
function Say(utterance, callback) {
console.log('Говорю: ' + utterance);
if (!callback){
callback = function(){ };
}
chrome.runtime.sendMessage(utterance, callback);
console.log('stop recording');
if(rec.isRunning) rec.stop();
}
chrome.runtime.onMessage.addListener(function(request,sender,callback2) {
console.log('start recording');
if(!rec.isRunning) rec.start();
});
var bird = document.getElementById('logoPtica');
if(bird){
bird.className += 'bird icon-32 icon-Microphone icon-primary';
bird.title = 'SBIS Voice Helper';
// Google Web Speech API
var rec = new webkitSpeechRecognition(),
sHandler = new SpeechHandler();
rec.continuous = true;
rec.interimResults = true;
rec.lang = 'ru';
rec.onstart = function () {
//Say("Привет, хозяин");
rec.isRunning = true;
};
rec.onend = function () {
//Say("До скорой встречи, хозяин");
rec.isRunning = false;
};
rec.onresult = function (event) {
for (var i = event.resultIndex; i < event.results.length; ++i) {
if (event.results[i].isFinal) {
sHandler.parse(event.results[i][0].transcript);
}
}
};
// так работает в ie8
bird.onclick = function(){
if( rec.isRunning ) rec.stop(); else rec.start();
};
}