2

I have a chatbot which runs in electron and I need to add speech to text there. I used window.SpeechRecognition and window.webkitSpeechRecognition but it seems now chrome is not supporting to speech recognition in electron. Is there a way that I can enable speech to text in electron. Below is my code which I've tried.

function listen() {
    let mic = document.getElementById('mic');
    mic.style.color = 'red';
    mic.className = 'animated pulse infinite';
    let SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
    var hear = new SpeechRecognition();
    hear.continuous = false;
    hear.lang = 'en-IN';
    hear.start();
    hear.onresult = function (e) {
        mic.style.color = 'black';
        mic.className = '';
        userVoiceText = e.results[0][0].transcript;
        hear.stop();
        createSender(userVoiceText);
        respond(userVoiceText);
    }
}

This is a must need requirement for my app. Suggestions for any workaround or API is appreciated.

shamila
  • 1,280
  • 6
  • 20
  • 45

1 Answers1

0

You have to add this in your main process:

app.commandLine.appendSwitch('enable-features', 'WebSpeechAPI');
André
  • 1,602
  • 2
  • 12
  • 26