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:
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:
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.