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

speechToText.cancel and speechToText.stop break flutterTts.speak #454

Closed AaEll closed 5 months ago

AaEll commented 6 months ago

Expected behavior: flutterTts.speak('this sentence');
will result in hearing the spoken sentence

Observed behavior flutterTts.speak('this sentence');
no sound is output

Flutter Doctor [✓] Flutter (Channel stable, 3.10.6, on macOS 13.5.1 22G90 darwin-arm64, locale en-US) [✓] Android toolchain - develop for Android devices (Android SDK version 33.0.2) [✓] Xcode - develop for iOS and macOS (Xcode 14.3.1) [✓] Chrome - develop for the web [✓] Android Studio (version 2022.2) [✓] VS Code (version 1.81.1) [✓] Connected device (3 available) [✓] Network resources

Device IPhone 14 Simulator on Mac

  final speechToText = SpeechToText();
  final flutterTts = FlutterTts();

Future<void> setupDeps() async {
    await speechToText.initialize();
    await speechToText.hasPermission;
    await flutterTts.setSharedInstance(true);
    await flutterTts.awaitSpeakCompletion(true);
}

void initState(){
    super.initState();
    setupDeps();
}

Future<void> speakTextNoListen() async {
    await speechToText.listen();
    await speechToText.cancel(); // OR speechToText.stop();

    flutterTts.speak('this sentence');    
}
sowens-csd commented 6 months ago

I think you're on the wrong forum. You're looking for the closely related project text to speech, this is the speech to text project. Pretty confusing naming, sorry about that. Basically we listen when you talk, they talk when you tell them what to say. Good luck getting an answer!

AaEll commented 6 months ago

I understand, the issue comes when using both libraries together.

flutterTts.speak('this sentence');

Works as intended, BUT this does not work

await speechToText.listen(); await speechToText.cancel(); // OR speechToText.stop(); flutterTts.speak('this sentence');

sowens-csd commented 6 months ago

I think you need to wait for the status callback from STT to report that it has stopped listening before trying to use the sound system again. Let me know if that helps.