-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathspeechRecognition.js
More file actions
45 lines (31 loc) · 830 Bytes
/
speechRecognition.js
File metadata and controls
45 lines (31 loc) · 830 Bytes
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
var SpeechRecognition = window.webkitSpeechRecognition;
var recognition = new SpeechRecognition();
var input_field = $('#textbox');
var instructions = $('instructions');
var text = '';
recognition.continuous = true;
recognition.onresult = function(event) {
var current = event.resultIndex;
var transcript = event.results[current][0].transcript;
text += transcript;
console.log(transcript);
input_field.val(text);
};
recognition.onstart = function() {
console.log("starting");
}
recognition.onspeechend = function() {
console.log("ending");
}
recognition.onerror = function(event) {
console.log(event.error);
}
$('#start-btn').on('click', function(e) {
if (text.length) {
text += ' ';
}
recognition.start();
});
input_field.on('input', function() {
text = $(this).val();
})