Flo
Flo

Reputation: 21

Using Javascript Webspeech Api in Electronjs

I wanted to write a simple voice recognition app on electron.

I already tried it as a simple webpage in chrome, where everything worked perfectly fine. In electron however I dont get any console outputs.

window.SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;

const recognition = new SpeechRecognition();

recognition.addEventListener('result', e => {
   console.log(e.results)
})

recognition.start();

The output that should appear (and appeared in Chrome) is:

enter image description here

I would really appreciate any help.

Upvotes: 2

Views: 1111

Answers (1)

Damien
Damien

Reputation: 4103

SpeechRecognition is a Google proprietary technology and it's using a a Google API to make an HTTP request. Chrome has an API_KEY but you have to specify your own Google API_KEY in your electron process environment variables. You have the same issues with the navigator.geolocation API: https://github.com/electron/electron/issues/7306

In your main.js file, before to call the SpeechRecognition API:

process.env.GOOGLE_API_KEY = "<GOOGLE API KEY>";

Upvotes: 1

Related Questions