12

I'm trying for hours to make this electron speech recognition work. The following code works in normal browser :

if (window.SpeechRecognition === null ){
    console.log("Speech Recognition is not supported.");
  }else {
    let recognizer  = new window.SpeechRecognition();

    recognizer.continuous = true;
    recognizer.lang = "en-US";
    recognizer.language = "English";

    recognizer.onresult = function (ev){
      console.log("Recognition result: ", event);
      displayVoice.value == "";
    }
    recognizer.onerror = function (ev){
      console.log("Recognition error: ", ev);
    }
    // recognizer.interimResults = true;
    recognizer.start();
  }

But when switching to electron i get this:

SpeechRecognition network error when working with electron / chromium browser

This means:

Network communication required for completing the recognition failed. (taken from MDN)

I have the GOOGLE_API_KEY set up in main.js.

process.env.GOOGLE_API_KEY = 'NIzaadwINWVhlqbjjklajwdBp2zjcFxnD3O3cBwc'; - (it's false stuff don't worry).
// process.env.GOOGLE_DEFAULT_CLIENT_ID = "95131180798735604-4k0pfsc6g.apps.googleusercontent.com"
// process.env.GOOGLE_DEFAULT_CLIENT_SECRET = "2kkkWCawzzlawuruhvdddwd_F1nqwFMUklUjYUTsft"
const path = require('path');
const url = require('url');
const {app, BrowserWindow} = require('electron');
...

There have been a number of questions on this topic, i tried them all. here here and here and many more.

The environment variable setup idea is explained here.

Also i discovered something interesting that might be relevant.

When I changed the environment variables as suggested here: enter image description here

But then the speech recognition stopped working in the normal Chrome browser. I think it overrides the default Chrome key. (Chrome it uses google servers to do the recognition)

I removed back the env variables - Chrome works again.. electron doesn't. I have billing enabled for this keys.

I can't believe that everybody failed to integrate this feature in electron. Speech recognition is important. I have no idea what else i should be doing.

Is it rely not possible to do speech recognition in electron? Then what i'm missing here..

UPDATE:

i see that SpeechRecognition.serviceURI was removed form chrome - looks like this parameter was intended for implementing a custom speech recognition solution. I found this thread - why was serviceURI removed from chrome.

AIon
  • 12,521
  • 10
  • 47
  • 73
  • 2
    Are you using https? – The scion Nov 18 '17 at 17:17
  • @the scion - I wasn't aware there is an https option - this google api thing happens behind the scenes in electron. But thanks for suggestion, I will start looking around, do you know how to configure https in electron? (in the browser, yes i'm using https) – AIon Nov 18 '17 at 17:47
  • 2
    I don't have a lot of experience with electron, but when I worked with speech recognition and Chrome there was a big issue of https and http. Chorme support speech recognition only over https protocol since version of 47. – The scion Nov 18 '17 at 17:52
  • @the scion thank you, i think you might be right. I will start testing it soon. Found this which is related. [electron-certificates-network](https://stackoverflow.com/questions/38676209/electron-certificates-network) – AIon Nov 18 '17 at 17:56

1 Answers1

3

As I mention in the comments if you are using Chrome with version higher then 47, you must do all the communication with the browser API via https protocol. The API of speech recgnition in Chrome calls WebRTC.

no-more-http-for-webrtc-on-chrome-only-https

The scion
  • 1,001
  • 9
  • 19