How to detect if webkitSpeechRecognition actually works in a browser

Viewed 1362

Edge claims to support webkitSpeechRecognition, but it doesn't work (discussion here, doesn't work on websites meant for testing, like this mozilla one, with the error "Error occurred in recognition: language-not-supported" despite my US english UI).

How can I detect if webkitSpeechRecognition is actually supported? I tried to filter out Edge by looking at the user agent, but it shows up as Chrome, and I'd prefer to just use feature detection rather than looking at the user agent anyway. I'd like to check this without requesting microphone permission (if I did request microphone permission, I'd have to wait for them to accept, and then see the language-not-supported error). Is there a simple way to check this, similar to just checking the value of window["webkitSpeechRecognition"] (which is defined in Edge, despite not working)?

1 Answers

If you want to check the support for webkitSpeechRecognition then you can refer to the JS code example below.

if ('SpeechRecognition' in window || 'webkitSpeechRecognition' in window) 
{
  console.log("speech recognition API supported");
} 
else 
{
  console.log("speech recognition API not supported")
}

Output in MS Edge 88.0.705.56:

enter image description here

However, if you directly try to make a test using webkitSpeechRecognition then it will not work.

It looks like this feature is currently under development and to use it we need to enable it by passing the command line arguments.

I suggest you refer to the steps below.

  1. Create a shortcut of the Edge chromium-browser.
  2. Right-click the shortcut file and go to Properties.
  3. Under Shortcut tab, in the Target textbox, add --enable-features=msSpeechRecognition after the msedge.exe path. Make sure to add 1 space between the path and command-line argument.

It should look like below.

enter image description here

  1. Click on the OK button to close the properties window.
  2. Launch the Edge browser via shortcut and visit any sample code example for SpeechRecognition. Here I am making a test with this example.

Output in MS Edge 88.0.705.56:

enter image description here

Related