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);
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.