Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

182
Views
webkitSpeechRecognition always requesting microphone access every time I run the function that calls it

I'm making a virtual assistant with html and js, and it works, but every time you press the "Ask something" button, it will request microphone access, even after I gave it access before. Is there any way around that? I think it might be that I'm running it directly from my folder, so would it help if I got it on a server or something? Here is my code:

<!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>

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!