-
Notifications
You must be signed in to change notification settings - Fork 0
/
voice.html
39 lines (33 loc) · 1.08 KB
/
voice.html
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
<!DOCTYPE html>
<html>
<head>
<title>Live Speech Recognition</title>
</head>
<body>
<button id="start" onclick="startRecognition()">Start Recognition</button>
<button id="end" onclick="stopRecognition()">Stop Recognition</button>
<p id="output"></p>
<script>
const output = document.getElementById('output');
let recognition;
function startRecognition() {
recognition = new webkitSpeechRecognition() || new SpeechRecognition();
recognition.lang = 'en-US'; // Set the language for speech recognition
recognition.continuous = true; // Enable continuous listening
recognition.onresult = function(event) {
const transcript = event.results[event.results.length - 1][0].transcript;
output.textContent += transcript;
};
// recognition.onend = function() {
// recognition.start(); // Restart the recognition when it stops
// };
recognition.start();
}
function stopRecognition() {
recognition.stop();
// Stop the continuous recognition
output.innerHTML=""
}
</script>
</body>
</html>