简体   繁体   English

语音识别麦克风不工作

[英]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.当我在 app.js 文件中进行一些更正时,我可以看到麦克风闪烁两次然后死亡。 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 :因此,如果您需要连续的结果,您应该将该属性设置为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 https://developer.mozilla.org/en-US/docs/Web/API/SpeechRecognition https://developer.mozilla.org/en-US/docs/Web/API/SpeechRecognition/continuous

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM