csdcorp / speech_to_text

A Flutter plugin that exposes device specific text to speech recognition capability.
BSD 3-Clause "New" or "Revised" License
351 stars 218 forks source link

even though I set listenFor and pauseFor value, it won't wait and force finished listening #450

Closed kotran88 closed 6 months ago

kotran88 commented 6 months ago

whole code is as below I want it to listen my voice for more or less 30seconds even though I pause speaking, it won't work. just 1 or 2 second of pausing goes toprint('onStatus: $val') here.

saying on terminal : onStatus: done


  void startVoiceListen() async {
    print("startVoiceListen...");
    print(_isListening);
    if (!_isListening) {
      print("false..so initialize...");
      bool available = await speech.initialize(
finalTimeout: Duration(seconds: 30),
        onStatus: (val) => {print('onStatus: $val')},
        onError: (val) => {print('onError: $val')},
      );
      if (available) {
        if (Platform.isIOS) {
          dingplayer.play(AssetSource("ding.mp3"));
        }
        setState(() => _isListening = true);
        speech.listen(
          localeId: "ko",
          listenFor: Duration(minutes: 1),
          pauseFor: Duration(seconds: 10),
          onResult: (val) => setState(() {
            print("final value is : ${val.finalResult}");
            print("value is : $val");

            textarea.text = val.recognizedWords;
            print('TextFormField text : ' + textarea.text);
            if (val.hasConfidenceRating && val.confidence > 0) {
              _confident = val.confidence;
            }
          }),
        );
      }
    } else {
      setState(() => _isListening = false);
      speech.stop();
    }
  }
sowens-csd commented 6 months ago

Is this on Android or iOS or the web?

kotran88 commented 6 months ago

@sowens-csd for now, I'm testing with android latest version 13. flutter doctor says

[!] Flutter (Channel stable, 3.13.9, on macOS 14.0 23A344 darwin-arm64 (Rosetta), locale ko-KR) ! Warning: dart on your path resolves to /opt/homebrew/Cellar/dart/2.18.6/libexec/bin/dart, which is not inside your current Flutter SDK checkout at /Users/pedrojung/Downloads/flutter. Consider adding /Users/pedrojung/Downloads/flutter/bin to the front of your path. [!] Android toolchain - develop for Android devices (Android SDK version 33.0.2) ! Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses [✓] Xcode - develop for iOS and macOS (Xcode 15.0.1) [✓] Chrome - develop for the web [✓] Android Studio (version 2022.3) [✓] Android Studio (version 2020.3) [✓] VS Code (version 1.70.2) [✓] Connected device (4 available) [✓] Network resources

sowens-csd commented 6 months ago

Yes, that is expected behaviour.

On Android there is a system imposed pause time that cannot be overridden. The pauseFor and listenFor are the maximum pauses, on Android they may be shorter than these values. There are Android settings in the API that are supposed to allow those values to be overridden but I have never found a device that respects those settings.