javascriptmicrophonebrave

SpeechRecognition emitting network error event in Brave Browser


I am seeing a network error when I am trying to use the SpeechRecognition API in Brave. It's working just fine in Chrome and Safari in OS X. Is that simply not working in Brave or is there a way to make it work? Please have a look at the jsfiddle below for a 'working' example. I would have expected SpeechRecognition || webkitSpeechRecognition to be undefined if Speech Recognition is not supported.

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/


Solution

  • As you discovered, the SpeechRecognition API is not currently supported in the Brave browser. A Brave developer explained this in 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.

    Without developer support for a Brave-specific implementation of the API in question, it will not function as it does in more popular browsers.

    To your question about why SpeechRecognition || webkitSpeechRecognition is truthy, it's likely because the Chromium core for Brave is returning something that would indicate support.