forked from victorqribeiro/audio2text
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.js
40 lines (30 loc) · 865 Bytes
/
main.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
32
33
34
35
36
37
38
39
40
window.SpeechRecognition = window.webkitSpeechRecognition || window.SpeechRecognition;
const recognition = new window.SpeechRecognition();
recognition.lang = 'pt-BR';
recognition.continuous = true;
recognition.interimResults = true;
recognition.onresult = (e) => {
if(e.results[0].isFinal)
document.body.innerHTML = ( e.results[0][0].transcript );
};
recognition.onaudiostart = e => {
console.log("audio capture started");
}
recognition.onaudioend = e => {
console.log("audio capture ended");
}
const audio = new Audio();
audio.src = "brasil.ogg";
audio.preload = "auto";
audio.volume = 0.2 ;
audio.oncanplay = () => {
console.log('ready');
}
audio.onended = () => {
recognition.stop();
}
document.body.innerHTML = "Clique em qualquer lugar na página...";
document.addEventListener("click",function(){
recognition.start();
audio.play();
});