-
Notifications
You must be signed in to change notification settings - Fork 3
/
igor-initializer.js
48 lines (39 loc) · 1.02 KB
/
igor-initializer.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
$(document).ready(function () {
var recognition = new webkitSpeechRecognition();
recognition.continuous = true;
recognition.interimResults = true;
recognition.lang = "en";
recognition.onresult = function (e)
{
$('#input-display').html('');
for (i = 0; i < e.results.length; i++)
{
for (j = 0; j < e.results[i].length; j++)
{
$('<span />').text(e.results[i][j].transcript)
.addClass(e.results[i].isFinal ? 'sure' : 'guess')
.appendTo($('#input-display'));
}
if (e.results[e.results.length - 1].isFinal)
{
// Process only final messages
message = $('#input-display').text();
console.log("processing");
console.log(message);
console.log(e.results[i]);
}
}
}
recognition.onerror = function (e)
{
console.log("error!");
console.log(e);
recognition.start();
}
recognition.onend = function ()
{
console.log("restarting");
recognition.start();
}
recognition.start();
});