0

I have a web app and I want to use speech recognition Web API. The idea that I'm planning to do is using speech recognition for input and also for some commands.

I have created two speech recognition one for input and one for commands. Sometimes it works but it has many errors and issues due to both speech recognition running at the same time even when using the .stop() function before the other start then back listening to the commands.

Does web speech API in javascript support two running speech recognition in one web app? if not, what is the best solution for that idea? because on page loading the web should listening for commands and on press button also need to speech recognition to fill the input.

Here is an example of the code to explain the idea, each speech recognition will have it is own features as lang, grammar and so on.

var SpeechRecognition = SpeechRecognition || webkitSpeechRecognition
var SpeechGrammarList = SpeechGrammarList || webkitSpeechGrammarList
var SpeechRecognitionEvent = SpeechRecognitionEvent || webkitSpeechRecognitionEvent
speechRecognitionList.addFromString('#JSGF V1.0;', 1);

var ForInput = new SpeechRecognition();
ForInput.grammars = speechRecognitionList;
ForInput.continuous = true;
ForInput.lang = 'en-US';
ForInput.interimResults = true;
ForInput.maxAlternatives = 1;

var ForCommand = new SpeechRecognition();
ForCommand.grammars = speechRecognitionList;
ForCommand.continuous = false;
ForCommand.lang = 'en-US';
ForCommand.interimResults = false;
ForCommand.maxAlternatives = 1;

Thanks

  • Why can't you just use one and check what was recognized to see if it was a command or just text. Or use some boolean to determine which "mode" you want to use? – John Apr 09 '21 at 23:24
  • Thanks, I'm thinking of the same idea and how I can develop it. I didn't think to apply it because I'm planning to use a different language for the input speech. and for the commands, it should support only English currently. – Tech. Engineer Apr 12 '21 at 20:14
  • Did you try using `abort()` instead of `stop()`? – jbflow Jul 24 '21 at 19:07

0 Answers0