I'm making an flutter app with the flutter_tts package , and i want to change the UI according to the status of the tts, like if it finished reading then the UI will change.
so how to know the status of the tts?
I'm making an flutter app with the flutter_tts package , and i want to change the UI according to the status of the tts, like if it finished reading then the UI will change.
so how to know the status of the tts?
Take a look at the flutter_tts documentation.
They provide a method
await flutterTts.awaitSpeakCompletion(true);
which you can await until the TTS finishes, and then do whatever you want afterwards.
// assume it's started already
await flutterTts.awaitSpeakCompletion(true);`
// tts will have finished
debugPrint("tts has finished");
You can use whenComplete methode and put a setState(){} inside it and when flutterTts completes your code will de excuted.
await flutterTts.awaitSpeakCompletion(true).whenComplete(() {
setState(() {
// Change UI
);
});
});
but it's better to use :
flutterTts.setStartHandler(() {
setState(() {
// change UI
);
flutterTts.setCompletionHandler(() {
setState(() {
// change UI
);