Does it required to create new instance of SpeechRecognition after each speech?
var recognition = new SpeechRecognition();
recognition.start();
Or just stop() and call the start() func again?
recognition.stop();
recognition.start();
cancel() The cancel() method of the SpeechSynthesis interface removes all utterances from the utterance queue. If an utterance is currently being spoken, speaking will stop immediately.
Support for Web Speech API speech recognition is currently limited to Chrome for Desktop and Android — Chrome has supported it since around version 33 but with prefixed interfaces, so you need to include prefixed versions of them, e.g. webkitSpeechRecognition .
The speech recognition interface lives on the browser's window object as SpeechRecognition in Firefox and as webkitSpeechRecognition in Chrome. Start by setting the recognition interface to SpeechRecognition (regardless of the browser) using: window. SpeechRecognition = window. webkitSpeechRecognition || window.
Only 1 instance is necessary to interact with the SpeechRecognition object.
You can start the listener with start(). You can stop the listener with stop() or abort().
The abort() method slightly differs from the stop method:
The abort() method of the Web Speech API stops the speech recognition service from listening to incoming audio, and doesn't attempt to return a SpeechRecognitionResult.
Here is the example straight from the docs:
var recognition = new SpeechRecognition();
var speechRecognitionList = new SpeechGrammarList();
speechRecognitionList.addFromString(grammar, 1);
recognition.grammars = speechRecognitionList;
var diagnostic = document.querySelector('.output');
var bg = document.querySelector('html');
document.body.onclick = function() {
recognition.start();
console.log('Ready to receive a color command.');
}
abortBtn.onclick = function() {
recognition.abort();
console.log('Speech recognition aborted.');
}
recognition.onspeechend = function() {
recognition.stop();
console.log('Speech recognition has stopped.');
}
Find out more from the SpeechRecognition docs.
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