问题描述
我一直在关注 this 并补充了各种 YouTube 视频和堆栈溢出问题.但是,我不确定为什么我的语音识别不起作用.我被问到很少允许使用麦克风.
我希望用户麦克风拾取用户的语音并将其附加到某个输入值.这是我的代码:
const 识别 = new SpeechRecognition();识别.interimResults = true;var 识别 = new SpeechRecognition();识别.onresult = 函数(事件){if (event.results.length > 0) {name.value = event.results[0][0].transcript;}}识别.addEventListener(结束",()=> {识别开始();});var 识别 = new SpeechRecognition();识别.onresult = 函数(事件){if (event.results.length > 0) {location.value = event.results[0][0].transcript;}}识别.addEventListener(结束",()=> {识别开始();});var 识别 = new SpeechRecognition();识别.onresult = 函数(事件){if (event.results.length > 0) {state.value = event.results[0][0].transcript;文档.care.submit();}}识别.addEventListener(结束",()=> {window.location.pathname = '/care';文档.care.submit();});
以下是我遇到的错误:
未捕获的引用错误:未定义识别在 HTMLButtonElement.onclick
未捕获的语法错误:已声明标识符识别"
无法加载资源:net::ERR_FAILED
我使用 SpeechRecogition 已经有一段时间了,一开始可能会非常棘手.但是,我发现这个要点对我非常很有帮助.希望这段代码可以帮助您像对我一样理解 SpeechRecogition.
要点:https://gist.github.com/strongSoda/27f4caf1335e3d08e10cf7> Youtube 教程(与代码对应):https://www.youtube.com/watch?v=4eIRrowvLRk I've been following this and supplementing it with various youtube videos and stack overflow questions. But, I am not exactly sure why my speech recognition is not working. I am asked about allowing microphone access rarely. I want the user microphone to pick up the user's speech speech and append it to a certain input value. Here's my code: Here are the errors I am getting: Uncaught ReferenceError: recognition is not definedat HTMLButtonElement.onclick Uncaught SyntaxError: Identifier 'recognition' has already been declared Failed to load resource: net::ERR_FAILED I've worked with SpeechRecogition for a bit, and it can be very at first tricky. However, I found that this gist is very helpful for me. Hopefully this code can help you understand SpeechRecogition more like it did with me. Gist: https://gist.github.com/strongSoda/27f4caf1335e3d03accf708e1fcdcbf0 Youtube Tutorial (that corresponds with the code): https://www.youtube.com/watch?v=4eIRrowvLRk 这篇关于为什么我在 js 上的语音识别不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!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();
});