我一直在关注this https://javascript.plainenglish.io/how-to-use-speech-recognition-and-speech-synthesis-in-javascript-9bcb213f6ddd并用各种 YouTube 视频和堆栈溢出问题对其进行补充。但是,我不太确定为什么我的语音识别不起作用。很少有人问我是否允许访问麦克风。
我希望用户麦克风拾取用户的语音并将其附加到某个输入值。这是我的代码:
const recognition = new SpeechRecognition();
recognition.interimResults = true;
var recognition = new SpeechRecognition();
recognition.onresult = function(event) {
if (event.results.length > 0) {
name.value = event.results[0][0].transcript;
}
}
recognition.addEventListener("end", () => {
recognition.start();
});
var recognition = new SpeechRecognition();
recognition.onresult = function(event) {
if (event.results.length > 0) {
location.value = event.results[0][0].transcript;
}
}
recognition.addEventListener("end", () => {
recognition.start();
});
var recognition = new SpeechRecognition();
recognition.onresult = function(event) {
if (event.results.length > 0) {
state.value = event.results[0][0].transcript;
document.care.submit();
}
}
recognition.addEventListener("end", () => {
window.location.pathname = '/care';
document.care.submit();
});
以下是我收到的错误:
未捕获的引用错误:识别未定义
在 HTMLButtonElement.onclick 处
未捕获的语法错误:标识符“识别”已被声明
无法加载资源:net::ERR_FAILED
我已经使用 SpeechRecogition 工作了一段时间,一开始可能会非常棘手。然而,我发现这个要点是very对我有帮助。希望这段代码可以帮助您像我一样理解语音识别。
Gist: https://gist.github.com/strongSoda/27f4caf1335e3d03accf708e1fcdcbf0 https://gist.github.com/strongSoda/27f4caf1335e3d03accf708e1fcdcbf0
Youtube 教程(与代码相对应):https://www.youtube.com/watch?v=4eIRrowvLRk https://www.youtube.com/watch?v=4eIRrowvLRk
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)