setStartHandler, setCompletionHandler does not work on Windows
setStartHandler, setCompletionHandler, etc. handlers does not work on Windows. Only on other platforms. On Windows there is no effect. These handlers are not called by FlutterTTS on Windows. So you can not determine if it is speeking or not. Thank you in advance for the bug fix.
@zsmiklos this isn't a bug as it's not implemented on Windows. This would be an enhancement to get it added.
Thank you. On Windows how can you detect the end of a TTS speech? If there is no other way, then is this not a bug? Thanks.
@zsmiklos win32: https://github.com/dlutton/flutter_tts/blob/112b9317dd0397324cb1d8e4126cd772d583229b/windows/flutter_tts_plugin.cpp#L326 uwp is a bit more complicated, but you can detect that mplayer is closing. https://github.com/dlutton/flutter_tts/blob/112b9317dd0397324cb1d8e4126cd772d583229b/windows/flutter_tts_plugin.cpp#L78
Thank you very much! :)
Sorry it does not work. I'am using flutter_tts: ^3.5.1, but listeners do not working on Windows. (setStartHandler, setCompletionHandler, etc, none of them, and nor awaitSpeakCompletion). What can be the reason of the problem?
@zsmiklos This is still not implemented. Don't you want to give it a try and implement it based on my previous suggestions? awaitSpeakCompletion should work though. Can you give me an example how it's not working as expected? Best would be to open another ticket, since that's a different topic, not the one that is indicated in the subject here.
In the version 3.5.1 in the windows\flutter\ephemeral.plugin_symlinks\flutter_tts\windows\flutter_tts_plugin.cpp at line 326, there is what you adviced:
RegisterWaitForSingleObject(&addWaitHandle, speakCompletionHandle, (WAITORTIMERCALLBACK)&setResult, speakResult.get(), INFINITE, WT_EXECUTEONLYONCE);
and at line 78:
mPlayer.MediaEnded([=](Windows::Media::Playback::MediaPlayer const& sender,
These are in the version 3.5.1, I does not needed to edit the flutter_tts_plugin.cpp file.
Don't you want to give it a try and implement it based on my previous suggestions?
So I tried it and sorry it does not work.
My code is the following:
curTTS = new FlutterTts();
curTTS.setStartHandler(() {
print("curTTS.setStartHandler");
});
curTTS.setCompletionHandler(() {
print("curTTS.setCompletionHandler");
});
curTTS.setCancelHandler(() {
print("curTTS.setCompletionHandler");
});
curTTS.setContinueHandler(() {
print("curTTS.setContinueHandler");
});
curTTS.setPauseHandler(() {
print("curTTS.setPauseHandler");
});
curTTS.setErrorHandler((message) {
print("curTTS.setErrorHandler");
});
and the code for starting TTS:
await curTTS.setLanguage(locale.languageCode);
curTTS.speak(toSpeakStr); // without await
App started to speak the text but the listeners are not called by flutter_tts.
awaitSpeakCompletion should work though.
and with this code:
curTTS.speak(toSpeakStr); // without await
print("awaitSpeakCompletion started");
await curTTS.awaitSpeakCompletion(true); // true/false does not work
print("awaitSpeakCompletion ended");
speak starts but the awaitSpeakCompletion immediately finished. It does not wait to the end of the speach. And listeners are not called.
@zsmiklos setStartHandler is not implemented. The code I linked in is a suggestion for a starting point, that is a way to set up a callback, you could use that to implement setStartHandler. I agree that this is really useful, so if I had time for this library, probably I would do this. But I don't have. For awaitSpeakCompletion, I asked you to open another ticket, it would be useful for others facing the same issue. But anyways, awaitSpeakCompletion is a setting, you should call it first and call curTTS.speak(toSpeakStr) after that. This is true for all other settings, e.g. changing the pitch during speak will affect only the next call of curTTS.speak.
I'll start working on this now.