Microsoft Edge中的语音识别API(未定义)

问题描述 投票:0回答:1

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

任何人对此情况都不清楚,或者知道如何使语音识别在JavaScript中与edge一起使用吗?

欢呼声

javascript api speech-recognition microsoft-edge speech-to-text
1个回答
0
投票

截至2020年6月4日,Edge Chromium并不真正支持Web Speech API的语音识别部分。 Microsoft似乎正在为Edge Chromium处理。对于非Edge的Edge,它可能永远无法使用。

developer.microsoft.com错误地说它是“受支持的”,但也说“正在工作的草稿或等效文件”。

developer.mozilla.org compatibility table还错误地指出Edge支持该功能。

[caniuse正确显示了Edge Chromium不支持它,即使它的行为类似,但是没有触发适当的事件。

除Chrome和Chromium之外,我看到的与Web Speech API一起使用的语音识别部分的唯一其他浏览器是Brave和Yandex。 Yandex可能连接到俄罗斯的服务器以处理语音识别。它做得不好。至少用英语。

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

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;
}
© www.soinside.com 2019 - 2024. All rights reserved.