javascript - Brave 浏览器中的 SpeechRecognition 发出网络错误事件

标签 javascript microphone brave

当我尝试使用 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-' ; 

}

https://jsfiddle.net/qomdcL6g/2/

最佳答案

正如您所发现的,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/

相关文章:

spring-boot - 微服务日志中的 TraceID

selenium - 如何在 Brave Web 浏览器上运行 Selenium 测试?

javascript - 如何使用jquery ajax重新加载带有表单内容的div

javascript - 如何停止jquery更改单个div上所有div的css

python - Python Speech_recognition无法检测到麦克风的音频

iphone - 如何以编程方式进行音频降噪?

html - HTML5麦克风保存到服务器上的文件或服务器上的进程

javascript - 如何使用 getclassbyelemententnames?

javascript - JavaScript 文本区域处理中的复制剪切粘贴功能

javascript - 检测用户是否在 JS 中使用 Brave