SHOW:
|
|
- or go back to the newest paste.
| 1 | <!-- saved from https://pastebin.com/3Kdt2x7c --> | |
| 2 | <!DOCTYPE html> | |
| 3 | <html> | |
| 4 | <head> | |
| 5 | <title>Speech Recognition</title> | |
| 6 | </head> | |
| 7 | <body> | |
| 8 | <h1>Speech Recognition</h1> | |
| 9 | <button onclick="startListening()">Start Listening</button> | |
| 10 | <button onclick="stopListening()">Stop Listening</button> | |
| 11 | <p id="result"></p> | |
| 12 | ||
| 13 | <script> | |
| 14 | let recognizer; | |
| 15 | let audioChunks = []; | |
| 16 | ||
| 17 | // Function to start speech recognition | |
| 18 | function startListening() {
| |
| 19 | recognizer = new window.webkitSpeechRecognition(); | |
| 20 | recognizer.continuous = true; | |
| 21 | recognizer.interimResults = true; | |
| 22 | recognizer.lang = "en-US"; | |
| 23 | recognizer.onresult = function(event) {
| |
| 24 | let result = event.results[event.results.length - 1]; | |
| 25 | if (result.isFinal) {
| |
| 26 | let text = result[0].transcript; | |
| 27 | console.log("You said: " + text);
| |
| 28 | document.getElementById("result").textContent = text;
| |
| 29 | } | |
| 30 | }; | |
| 31 | recognizer.onend = function() {
| |
| 32 | console.log("Speech recognition ended.");
| |
| 33 | }; | |
| 34 | recognizer.start(); | |
| 35 | } | |
| 36 | ||
| 37 | // Function to stop speech recognition | |
| 38 | function stopListening() {
| |
| 39 | recognizer.stop(); | |
| 40 | } | |
| 41 | </script> | |
| 42 | </body> | |
| 43 | </html> |