2
mounted() {
 window.SpeechRecognition = window.webkitSpeechRecognition || 
 window.SpeechRecognition;
 let finalTranscript = "";
 let recognition = new window.SpeechRecognition();

 recognition.interimResults = true;
 recognition.maxAlternatives = 10;
 recognition.continuous = true;

recognition.onresult = event => {
  let interimTranscript = "";
  for (
    let i = event.resultIndex, len = event.results.length;
    i < len;
    i++
  ) {
    let transcript = event.results[i][0].transcript;
    if (event.results[i].isFinal) {
      finalTranscript += transcript;
    } else {
      interimTranscript += transcript;
    }
  }

  console.log(finalTranscript + interimTranscript);
};
recognition.start();
}

cant get web speech API to work in my electron app, same code works well in the browser. Any possible reasons? I am using vue js with electron and the speech part is called when a component mounts.

jagz
  • 41
  • 3

1 Answers1

2

As you may already know, Electron is built on top of the Chromium open-source browser.

This discrepancy between the browser and Electron stems from the fact that Chromium does not include the Google API keys necessary to run certain webservices (e.g. Speech, Geolocation), while Chrome does (source: Chromium Browser vs. Google Chrome).

As of today, there exists a GOOGLE_API_KEY environment variable that adds a API key for your app, but it only works for the Geolocation webservice. You can verify this in the Electron source code, where this variable is only hooked into the ElectronBrowserClient::GetGeolocationApiKey() function.

For now, your best bet would be to look into implementing those under-the-hood Google APIs directly.

Erick
  • 1,138
  • 8
  • 15