2

As soon as I call rec.start() it calls onstart and then onend straight away, never goes into onresult.

Microphone is allowed for the web page, it asked once due to being https Using Chrome 81.0.4044.122 on osx, which is listed as supporting speechRecognition.

I am aware this is a not a stable feature within browsers, but running the annyang demo works, detecting my voice, and I believe that is using the same speechRecognition kit. https://www.talater.com/annyang/

Any ideas?

Here is my code

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;
}
macasas
  • 497
  • 6
  • 20

1 Answers1

1

Sorry guys, it was a browser issue.

Chrome said it had updated, but it actually still needed restarting, only seen after going into Chrome Preferences.

I now have 83.0.4103.83 on both desktop and Android tablet, and it appears to be working correctly.

macasas
  • 497
  • 6
  • 20