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)?
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)?
-
Why not instantiate it and wrap it in a
try/catch
? This is exactly one of those situations where you may want to do that. My US-language mac with Edge is having no issues with that web page. – somethinghere Commented Feb 1, 2021 at 23:32 - @somethinghere oh, hm, I just downloaded edge a few days ago, and the page doesn't work for me! I immediately get "Error occurred in recognition: language-not-supported". The answer below says "It looks like this feature is currently under development and to use it we need to enable it by passing the mand line arguments." — did you do that? I probably will use the try/catch way, but I'd prefer to not request microphone permission if the user isn't going to be able to use it – www Commented Feb 2, 2021 at 16:38
- No, but I might be using an older canary version, now that I think about it. Why not test in chrome for now, while microsoft is working on it? Just catch the error to decide if it works! – somethinghere Commented Feb 2, 2021 at 22:25
- Right, I just would prefer if there was a way to see if speech recognition was supported without first asking the user for microphone permission, which it seems like there may not be. – www Commented Feb 2, 2021 at 22:32
-
1
The presence of which object,
recognizer = new window["webkitSpeechRecognition"]()
? Yeah, that object is defined in Edge, it just doesn't recognize any text. Safari e.g. returns false forwindow["webkitSpeechRecognition"]
, so I have no problems there. You don't have to set the language (it defaults to user agent's language setting), but even if I do, I get the same error. And I get the same error on the mozilla example too :) – www Commented Feb 2, 2021 at 22:57
2 Answers
Reset to default 2If 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:
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 mand line arguments.
I suggest you refer to the steps below.
- Create a shortcut of the Edge chromium-browser.
- Right-click the shortcut file and go to Properties.
- Under Shortcut tab, in the Target textbox, add
--enable-features=msSpeechRecognition
after themsedge.exe
path. Make sure to add 1 space between the path and mand-line argument.
It should look like below.
- Click on the OK button to close the properties window.
- 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:
In addition, it's useful to check for errors (as shown in the above example source code, see below, https://www.google./intl/en/chrome/demos/speech.html): for instance audio might be disabled if not on a https website.
recognition.onerror = function(event) {
if (event.error == 'no-speech') {
start_img.src = '/intl/en/chrome/assets/mon/images/content/mic.gif';
showInfo('info_no_speech');
ignore_onend = true;
}
if (event.error == 'audio-capture') {
start_img.src = '/intl/en/chrome/assets/mon/images/content/mic.gif';
showInfo('info_no_microphone');
ignore_onend = true;
}
if (event.error == 'not-allowed') {
if (event.timeStamp - start_timestamp < 100) {
showInfo('info_blocked');
} else {
showInfo('info_denied');
}
ignore_onend = true;
}
};