flutterspeech-recognitionspeech-to-text

Flutter Speech to text not listening continuously


Working on Flutter speech to text conversion and using speech to text library, added below code for listening:

speech.listen(
          onResult: resultListener,
          listenFor: Duration(minutes: 10),
          localeId: _currentLocaleId,
          onSoundLevelChange: soundLevelListener,
          cancelOnError: false,
          partialResults: true);

App listening continuously in Emulator but stops listening automatically after few seconds in physical device. I had tried many libraries like speech recognition still same issue occurs. Everything works on emulator device, not in physical device.

Please give some suggestion about this.

Thanks in advance.


Solution

  • 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).