-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
25 lines (20 loc) · 715 Bytes
/
app.js
File metadata and controls
25 lines (20 loc) · 715 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
window.SpeechRecognition=window.SpeechRecognition || window.webkitSpeechRecognition;
const recognition= new SpeechRecognition();
recognition.interimResults=true;
const p=document.createElement('p');
const words = document.querySelector('.words');
words.appendChild(p);
recognition.addEventListener('result',e=>{
console.log(e.results);
const transcript = [...e.results]
.map(result => result[0])
.map(result => result.transcript).join(' ');
p.innerHTML=transcript;
if(e.results[0].isfinal) {
p=document.createElement('p');
words.appendChild(p);
p.textContent = transcript;
}
});
recognition.addEventListener('end',recognition.start);
recognition.start();