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.
The onerror property of the SpeechRecognition interface represents an event handler that will run when a speech recognition error occurs (when the error event fires.) mySpeechRecognition.onerror = function() { ...
The SpeechRecognition interface of the Web Speech API is the controller interface for the recognition service; this also handles the SpeechRecognitionEvent sent from the recognition service. Note: On Chrome, using Speech Recognition on a web page involves a server-based recognition engine.
Note: On some browsers, like Chrome, using Speech Recognition on a web page involves a server-based recognition engine. Your audio is sent to a web service for recognition processing, so it won't work offline. Creates a new SpeechRecognition object.
Check the Browser compatibility table carefully before using this in production. The SpeechRecognition interface of the Web Speech API is the controller interface for the recognition service; this also handles the SpeechRecognitionEvent sent from the recognition service.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With