Skip to content

Commit dd194c8

Browse files
committed
adding script wesbos#20
1 parent 9380db3 commit dd194c8

File tree

2 files changed

+4039
-0
lines changed

2 files changed

+4039
-0
lines changed

20 - Speech Detection/index-START.html

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,32 @@
1212
<script>
1313
window.SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
1414

15+
const recognition = new SpeechRecognition();
16+
recognition.interimResults = true;
17+
18+
let p = document.createElement('p');
19+
const words = document.querySelector('.words');
20+
words.appendChild(p);
21+
22+
recognition.addEventListener('result', e => {
23+
const transcript = Array.from(e.results)
24+
.map(result => result[0])
25+
.map(result => result.transcript)
26+
.join('')
27+
28+
p.textContent = transcript;
29+
if(e.results[0].isFinal) {
30+
p = document.createElement('p');
31+
words.appendChild(p);
32+
}
33+
if(transcript.includes('computer')) {
34+
console.log('Are you talking to me?');
35+
}
36+
});
37+
38+
recognition.addEventListener('end', recognition.start);
39+
40+
recognition.start();
1541

1642
</script>
1743

0 commit comments

Comments
 (0)