Web speech API stops listening after some time passes without input
You can listen to the end
event and then restart the recognition on the SpeechRecognition
object.
You should use a boolean flag for deciding (in the onend
event handler), when to restart the recognition (and when not to restart).
You could use the other recognition-related events for this.
E.g. Chrome triggers the following event handlers when recognition is started:
1. onstart
2. onaudiostart
(only if sound / speech is detected)
3. onsoundstart
4. onspeechstart
If no sound speech is detected, only the first 2 will be triggered, and then, after some timeout, the corresponding end
events (in reverse order).
Web speech recognition automatically disconnects
Depending on your browser and if any tabs are trying to access your mic, setting your SpeechRecognition object to continuous should work.
Use the code below for reference. The window.SpeechRecognition is just setting up the speech recognition.
window.SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
const recognition = new SpeechRecognition();
recognition.continuous = true;
You can also add an event listener for when your recognition disconnects and start back up the recognition of the web speech api.
recognition.addEventListener('end', () => {
recognition.start();
});
This article, from our code world, on the speech api also goes over storing the interim words spoken while it's continuous.
This worked for me on the Chrome browser.
If setting the recognition to continuous does not work, you may have to troubleshoot another service on your computer taking the microphone from your browser tab.
Flutter Speech to text not listening continuously
The Flutter speech to text libraries doesn't allow continuous listening because of privacy issues which is super annoying. The listenFor parameter is an upper bound for when to cut off if you can keep speaking for that long.
As an alternative, I would recommend using Flutter's platform specific implementation. This lets you have a much lower level control. (As a quick tip, even the Android SpeechRecognition library contains a timeout. But the Vosk api is able to do what you're looking for https://github.com/alphacep/vosk-api). If you're really keen, you can look at building your own IME to integrate with voice typing functionality (https://developer.android.com/guide/topics/text/creating-input-method).
Related Topics
How to Add a Button to a Preferencescreen
Facebook Authentication Without Login Button
Android Application Class Lifecycle
How to Use Android Canvas to Draw a Rectangle with Only Topleft and Topright Corners Round
Ontouchevent Not Working on Child Views
How to Implement Uncaughtexception Android
Getting Results of Nearby Places from User's Location Using Google Maps API in Android
How to Capture an Image in Background Without Using the Camera Application
Performing Action After Fragment Transaction Animation Is Finished
Calling Startintentsenderforresult from Fragment (Android Billing V3)
Get Context Inside Onclick(Dialoginterface V, Int Buttonid)
Android Edittext, Soft Keyboard Show/Hide Event
How to Add Parameters in Android Http Post
How to Setcontentview in a Fragment
Avoiding Content Type Issues When Downloading a File via Browser on Android