-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathvoicedetect.js
More file actions
35 lines (30 loc) · 1.08 KB
/
voicedetect.js
File metadata and controls
35 lines (30 loc) · 1.08 KB
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
window.SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
var stopRecog = new SpeechRecognition();
var str;
var finalString = '';
function startRecord() {
try {
const recognition = new SpeechRecognition();
stopRecog = recognition;
recognition.interimResults = true;
recognition.addEventListener('result', e => {
const transcript = Array.from(e.results)
.map(result => result[0])
.map(result => result.transcript)
.join('');
if (e.results[0].isFinal) {
console.log(transcript);
finalString = finalString + transcript + '\n';
acceptString(transcript);
document.getElementById('myinput').value = finalString;
recognition.stop();
}
});
//recognition.addEventListener('end', recognition.start);
recognition.start();
} catch (e) {
console.error(e);
$('.no-browser-support').show();
$('.app').hide();
}
}