Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Speech Recognition Microphone is not working

Can you please tell me why my microphone is not working ? When I made some correction in app.js file I can see microphone is blinking twice and then is death. I believe microphone is on. Any suggestion how to fix this problem ? Thank you

here is my code:

const msgEl = document.getElementById('msg')

window.SpeechRecognition = window.SpeechRecognition ||
window.webkitSpeechRecognition;

let recognition = new window.SpeechRecognition()


// start recognition
recognition.start();

function onSpeak(e) {
  const msg = e.results[0][0].transcript;
  console.log(msg)
  
}

recognition.addEventListener('result', onSpeak);

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

It’s working, but by default, the recognition service is not continuous, it will end after a single result or timeout. So if you need continuous results you should set the property as false:

let recognition = new window.SpeechRecognition()
recognition.continuous = true;

But now the new results will be appended to the recognition list everytime there is a new result, so you will have to modify the way you print the results:

function onSpeak(e) {
    let msg = e.results[e.results.length-1][0].transcript;
    console.log(msg)
}

And if you do not want it to end on timeout if there is no activity, you may try this:

recognition.onend = function() {
    console.log('Speech recognition has stopped. Starting again ...');
    recognition.start();
}

References:

https://developer.mozilla.org/en-US/docs/Web/API/SpeechRecognition
https://developer.mozilla.org/en-US/docs/Web/API/SpeechRecognition/continuous

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading