Flutter Speech to text not listening continuously

3,359

Solution 1

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

Solution 2

From speech_to_text.dart:

/// There is a time limit on listening imposed by both Android and iOS. The time /// depends on the device, network, etc. Android is usually quite short, /// especially if there is no active speech event detected, on the order /// of ten seconds or so.

In android SpeechRec stops after 2 or 3 seconds but in Ios it keeps listening until .stop() called.

Share:
3,359
Lavii
Author by

Lavii

Updated on December 20, 2022

Comments

  • Lavii
    Lavii over 1 year

    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.

  • Taazar
    Taazar almost 4 years
    The extra 0 at the end of the second link is making it invalid.
  • Faabass
    Faabass about 3 years
    Hi @izzelot, do you know if this changed in the last months? I have an app working with speech to text in Android, with a loop every 10 seconds, to have the speech working, but now as soon as it starts, I get time out error in initSpeechState
  • izzetot
    izzetot about 3 years
    Hi @Faabass, nothing has changed.