Estoy creando un asistente virtual con html y js, y funciona, pero cada vez que presiona el botón "Preguntar algo", solicitará acceso al micrófono, incluso después de que le di acceso antes. ¿Hay alguna forma de evitar eso? Creo que podría ser que lo esté ejecutando directamente desde mi carpeta, así que ¿sería útil si lo tengo en un servidor o algo así? Aquí está mi código:
<!DOCTYPE html> <html> <body> <button onclick="sListening()">Ask something</button> <br> <br> <div id="a"> <small>z</small>zZ... </div> <script> var SpeechRecognition = SpeechRecognition || webkitSpeechRecognition; var recognition = new SpeechRecognition(); // This runs when the speech recognition service starts recognition.onstart = function() { document.getElementById("a").innerHTML = "<b>!</b>" }; recognition.onspeechend = function() { // when user is done speaking recognition.stop(); } // This runs when the speech recognition service returns result recognition.onresult = function(event) { var transcript = event.results[0][0].transcript; process(transcript, "a"); var confidence = event.results[0][0].confidence; }; function ranarr(arr) { return arr[Math.floor(Math.random() * arr.length)]; } function process(text, div) { document.getElementById(div).innerText = text; text = text.toLowerCase(); var r = "I don't understand."; var hiarr = ['Sup?', 'Howdy.', 'Hello!', 'Well hello to you to!'] text = text.split(/([!,?,.,\s])/); if (text.includes("hi") || text.includes("hello")) { r = ranarr(hiarr) } let utterance = new SpeechSynthesisUtterance(r); speechSynthesis.speak(utterance); } // start recognition function sListening() { recognition.start(); } </script> </body> </html>