8000 completed challenge 20 · rohitkrai03/JavaScript30@6c456e9 · GitHub
[go: up one dir, main page]

Skip to content 8000

Commit 6c456e9

Browse files
committed
completed challenge 20
1 parent c125e0f commit 6c456e9

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

20 - Speech Detection/index.html

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,38 @@
66
</head>
77
<body>
88

9+
910
<div class="words" contenteditable>
1011
</div>
1112

1213
<script>
1314
window.SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
1415

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

1642
</script>
1743

0 commit comments

Comments
 (0)
0