只要我调用rec.start(),它就会直接调用onstart和onend,再也不会进入onresult。
麦克风是允许用于网页的,它曾经问过一次,因为在osx上使用Chrome81.0.4044.122是https,这被列为支持speechRecognition。
我知道这在浏览器中不是一个稳定的特性,但是运行安阳演示,检测我的声音,我相信这是使用相同的speechRecognition工具包。https://www.talater.com/annyang/
有什么想法吗?
以下是我的代码
if (!window.webkitSpeechRecognition) {
// not called, so assume browser supports webkitSpeechRecognition
alert('Your browser doesn\'t support speech to text.\nTry Chrome 33+ :)');
} else {
const promise = new Promise((resolve, reject) => {
const recognition = new webkitSpeechRecognition();
recognition.lang = lang;
recognition.continuous = true; // tried true and false
recognition.onstart = (e) => {
// called immediately after .start() as expected
console.log("onstart");
}
recognition.onend = () => {
// called immediately after onstart, not as expected
console.log("onend");
}
recognition.onresult = function(event) {
// never called, because it ended as soon as it started
console.log("onresult");
};
// also tried the following formats
// recognition.onresult = (event) => {};
// recognition.addEventListener('onresult', (event) => {};
// original example written like the following
// recognition.addEventListener('result', (event) => {};
recognition.start();
});
return await promise;
}发布于 2020-05-31 18:29:35
抱歉,伙计们,这是浏览器问题。
Chrome说它已经更新了,但实际上它仍然需要重新启动,只有在进入Chrome偏好设置后才能看到。
我现在在台式机和Android平板电脑上都有83.0.4103.83,看起来工作正常。
https://stackoverflow.com/questions/62114630
复制相似问题