本文介绍了Microsoft Edge 中的语音识别 API(未定义)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试使用 SpeechRecognition API(https://wicg.github.io/speech-api/#examples-recognition) 在最近的一个项目中.我目前正在使用浏览器 Microsoft Edge 并根据 https://caniuse.com/#feat=speech-recognition 它只是部分支持.从它的外观来看,Edge 似乎支持文本到语音"功能(SpeechSynthesis),但不支持语音识别功能.无论我在 EDGE 中为 SpeechRecognition(语音到文本)API 使用什么前缀,它总是无法识别它并说它未定义"

I have been attempting to use the SpeechRecognition API(https://wicg.github.io/speech-api/#examples-recognition) in a recent project.I am currently using the browser Microsoft edge and according to https://caniuse.com/#feat=speech-recognition it is only partially supported on there.From the looks of it, it seems that the "text to speech" feature is supported (SpeechSynthesis) on Edge but not the Speech Recognition feature. As no matter what prefix I use for the SpeechRecognition (Speech to text) API in EDGE it always does not recognise it and says it "is not defined"

任何人都清楚这种情况,或者知道如何让语音识别在 JavaScript 中与边缘一起工作?

Anyone have any clarity on this situation, or know how to get the Speech Recognition to work with edge in JavaScript?

干杯

推荐答案

截至 2020 年 6 月 4 日,Edge Chromium 并不真正支持 Web Speech API 的语音识别部分.Microsoft 似乎正在为边缘铬.它可能永远不适用于 Edge Legacy(非 Chromium).

As of 6/4/2020 Edge Chromium does not really support the Speech Recognition part of the Web Speech API. Microsoft seems to be working on it for Edge Chromium. It will probably never work for Edge Legacy (non-Chromium).

developer.microsoft.com 错误地说它是支持的";但也说,工作草案或等效".(更新:截至 2021 年 2 月 18 日,它现在说:不支持")

developer.microsoft.com says incorrectly that it is "Supported" but also says, "Working draft or equivalent". (UPDATE: As of 2/18/2021 it now says: "NOT SUPPORTED")

developer.mozilla.org 兼容性表还错误地表示 Edge 支持它.

developer.mozilla.org compatibility table also incorrectly says that it is supported in Edge.

caniuse 正确地表明 Edge Chromium 不支持它,即使它的行为类似于它是,但不会触发适当的事件.

caniuse correctly shows that it is not supported in Edge Chromium even though it acts like it is but the proper events are not fired.

除了 Chrome 和 Chromium 之外,我看到 Web Speech API 的语音识别部分使用的唯一其他浏览器是 Brave 和 Yandex.Yandex 可能连接到俄罗斯的服务器来处理语音识别.它没有做好.至少是英文的.目前,Brave 正在返回一个网络".错误.根据此 github Brave 讨论 Brave 必须向 Google 付费才能获得语音到文本服务.

The only other browsers besides Chrome and Chromium that I have seen the Speech Recognition part of the Web Speech API work with is Brave and Yandex. Yandex probably connects to a server in Russia to process the speech recognition. It does not do a good job. At least in English. At the moment Brave is returning a "Network" error. According to this github Brave discussion Brave would have to pay Google in order to get the speech to text service.

这里有一些快速代码,可用于测试语音识别是否在浏览器中工作并显示正文中的所有错误和事件.它仅适用于 https 协议.它似乎不适用于 codepen 或 jsfiddle.

Here is some quick code that can be used to test if Speech Recognition works in a browser and display all the errors and events in the body. It only works with https protocol. It does not seem to work with codepen or jsfiddle.

var msg = document.body;
var cr = "<br />";
var event_list = ["onaudioend", "onaudiostart", "onend", "onerror", "onnomatch", "onresult", "onsoundend", "onsoundstart", "onspeechend", "onspeechstart", "onstart"];
var sr = window.SpeechRecognition || window.webkitSpeechRecognition || false;

if (sr) {
    var recognition = new sr();
    event_list.forEach(function(e) {
        recognition[e] = function() {
            console.log(event);
            var txt = event.type + ": ";
            if (event.results) txt += event.results[0][0].transcript;
            if (event.error) txt += event.error; // "not-allowed" usually is because of not using secure https protocol
            if (event.type == "end")
                recognition.start(); // Start Recognition again
            msg.innerHTML += txt + cr;
        };
    });
    recognition.start();
}
else {
    msg.innerHTML += "This browser does not support SpeechRecognition or webkitSpeechRecognition." + cr;
}

这篇关于Microsoft Edge 中的语音识别 API(未定义)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-16 22:52
查看更多