当我尝试使用 SpeechRecognition API 时,我看到网络
错误在勇敢。它在 Chrome 和 OS X 中的 Safari 中运行得很好。这是否在 Brave 中不起作用,或者有没有办法让它工作?请查看下面的 jsfiddle 以获取“工作”示例。我本来期望SpeechRecognition ||如果不支持语音识别,则 webkitSpeechRecognition
为未定义
。
var SpeechRecognition = SpeechRecognition || webkitSpeechRecognition
var recognition = new SpeechRecognition();
recognition.lang = "en-US";
recognition.continuous = true;
recognition.interimResults = true;
recognition.start();
recognition.onresult = function(event) {
document.getElementById("text").innerHTML += event.results[0][0].transcript;
}
recognition.onstart = function(event) {
document.getElementById("text").innerHTML += '-start-' ;
}
recognition.onerror = function(event) {
document.getElementById("text").innerHTML += `-error ${event.error}-` ;
}
recognition.onend = function(event) {
document.getElementById("text").innerHTML += '-end-' ;
}
最佳答案
正如您所发现的,Brave 浏览器当前不支持 SpeechRecognition
API。一位 Brave 开发者在 a GitHub issue comment on the official Brave repository 中解释了这一点:
First of all: this isn't a problem with the microphone — it's a speech recognition API. Chrome ships with a non-standard API used for speech recognition. Websites which call the API are asking the browser to transcribe audio on behalf of the website and send the site the transcribed text (not the audio). When a site calls this API in Chrome, Chrome sends the raw audio to a Google server for transcription. The Google server parses the raw audio, and send the transcribed text back to Chrome. Chrome then passes the text to the website.
There are two problems with this. The simple straightforward problem is that Brave doesn't have access to that Google transcription service. It's a paid service from Google which Chrome gets to use for free. If Brave wanted to use it, we'd have to pay Google for the privilege. The second and much more substantial issue is that I don't think that anyone reasonably expects clicking a microphone icon on Duolingo to result in Brave sending their audio to Google.
Honestly, I think that this design in Chrome is absolutely ridiculous and I was completely flabbergasted when I learned how it worked. We've had some conversations with Google about it, and the outcome is more or less (1) that they don't see what the issue is, and (2) they won't give us access to this online transcription service unless we pay for it.
如果没有开发人员对相关 API 的 Brave 特定实现的支持,它就无法像在更流行的浏览器中那样发挥作用。
关于为什么SpeechRecognition || 的问题webkitSpeechRecognition
是真的,这可能是因为 Brave 的 Chromium 核心正在返回一些表示支持的内容。
关于javascript - Brave 浏览器中的 SpeechRecognition 发出网络错误事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74113965/