-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path20.js
28 lines (23 loc) · 870 Bytes
/
20.js
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
function speechRecognise() {
window.SpeechRecognition =
window.SpeechRecognition || window.webkitSpeechRecognition;
const recognition = new SpeechRecognition();
recognition.interimResults = true;
let p = document.createElement("p");
const words = document.querySelector(".words");
words.appendChild(p);
recognition.addEventListener("result", (e) => {
const transcript = Array.from(e.results)
.map((result) => result[0])
.map((result) => result.transcript)
.join("");
p.textContent = transcript;
if (e.results[0].isFinal) {
p = document.createElement("p");
words.appendChild(p);
}
});
recognition.addEventListener("end", recognition.start);
recognition.start();
}
window.addEventListener("DOMContentLoaded", speechRecognise);