Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <title>Speech Recognition</title>
- </head>
- <body>
- <h1>Speech Recognition</h1>
- <button onclick="startListening()">Start Listening</button>
- <button onclick="stopListening()">Stop Listening</button>
- <p id="result"></p>
- <script>
- let recognizer;
- let audioChunks = [];
- // Function to start speech recognition
- function startListening() {
- recognizer = new window.webkitSpeechRecognition();
- recognizer.continuous = true;
- recognizer.interimResults = true;
- recognizer.lang = "en-US";
- recognizer.onresult = function(event) {
- let result = event.results[event.results.length - 1];
- if (result.isFinal) {
- let text = result[0].transcript;
- console.log("You said: " + text);
- document.getElementById("result").textContent = text;
- }
- };
- recognizer.onend = function() {
- console.log("Speech recognition ended.");
- };
- recognizer.start();
- }
- // Function to stop speech recognition
- function stopListening() {
- recognizer.stop();
- }
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement