1

一旦我调用rec.start(),它就会立即调用onstart,然后立即调用onend,永远不会进入onresult。

网页允许使用麦克风,由于是 https Using Chrome 81.0.4044.122 on osx,它被询问过一次,它被列为支持语音识别。

我知道这在浏览器中不是一个稳定的功能,但运行 annyang 演示工作,检测我的声音,我相信这是使用相同的语音识别工具包。 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;
}
4

1 回答 1

0

对不起各位,是浏览器的问题。

Chrome 说它已经更新了,但它实际上仍然需要重新启动,只有在进入 Chrome 偏好设置后才能看到。

我现在在台式机和 Android 平板电脑上都有 83.0.4103.83,它似乎工作正常。

于 2020-05-31T10:29:35.437 回答