-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
31 lines (25 loc) · 1.15 KB
/
index.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
29
30
31
window.SpeechRecognition = webkitSpeechRecognition || SpeechRecognition;
// window.SpeechGrammarList = window.SpeechGrammarList || webkitSpeechGrammarList;
// window.SpeechRecognitionEvent = window.SpeechRecognitionEvent || webkitSpeechRecognitionEvent;
const recognition = new window.SpeechRecognition();
recognition.interimResults = true;
recognition.continuous = true;
recognition.lang = "ja-JP";
const listen = e => {
document.getElementById("results").value = "listening...";
e.target.classList.add("listening");
recognition.start();
};
const stop = e => {
recognition.stop();
document.getElementById("results").value = "";
document.getElementById("startBtn").classList.remove("listening");
};
document.getElementById("startBtn").onclick = listen;
document.getElementById("stopBtn").onclick = stop;
recognition.addEventListener("result", e => {
const spResult = [...e.results].map(result => result[0].transcript).join("\n");
document.getElementById("results").value = spResult;
document.getElementById("results").scrollTop = document.getElementById("results").scrollHeight;
});
// recognition.onend = () => recognition.start();