-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
99 lines (86 loc) · 2.8 KB
/
index.html
File metadata and controls
99 lines (86 loc) · 2.8 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<button id="start-stop">Start</button>
<div id="transcript"></div>
<script>
// check if the browser supports the Web Speech API
if ('speechSynthesis' in window) {
// get the start/stop button and transcript div
const startStopButton = document.getElementById('start-stop');
const transcriptDiv = document.getElementById('transcript');
// create a new SpeechRecognition object
const recognition =new webkitSpeechRecognition();
recognition.continuous = true;
//recognition.lang = 'en-IN';
recognition.maxAlternatives = 1;
recognition.interimResults = true;
let ftranscript="";
// define a function to handle the onresult event
recognition.onresult = (event) => {
// for (var i = event.resultIndex; i < event.results.length; ++i) {
// if (event.results[i].isFinal) {
// ftranscript= event.results[i][0].transcript;
// }else{
// // ftranscript= event.results[i][0].transcript;
// }
// }
// get the transcript of the spoken words
const transcript = event.results[0][0].transcript;
// update the transcript div with the transcript
transcriptDiv.innerText +=transcript;
// console.log(ftranscript);
//console.log()
// stop listening for speech
//recognition.stop();
};
// define a function to handle the onerror event
recognition.onerror = (event) => {
console.error(event.error);
};
recognition.onend = (event) => {
recognition.stop();
startStopButton.textContent = 'start';
console.error("ended");
};
// add a click event listener to the start/stop button
startStopButton.onclick = () => {
// check if the recognition is currently listening
if (startStopButton.innerText == "stop") {
// if it is, stop listening
recognition.stop();
startStopButton.textContent = 'start';
} else {
// if it isn't, start listening
recognition.start();
startStopButton.textContent = 'stop';
}
};
recognition.addEventListener('audiostart', () => {
console.log('Audio capturing started');
});
recognition.addEventListener('audioend', () => {
console.log('Audio capturing ended');
});
recognition.addEventListener('soundstart', () => {
console.log('Some sound is being received');
});
recognition.onspeechstart = () => {
console.log('Speech has been detected');
}
recognition.onspeechend = () => {
console.log('Speech has been not detected');
}
} else {
// if the browser does not support the Web Speech API, display an error message
console.error('Your browser does not support the Web Speech API');
}
</script>
</body>
</html>