From ff0c42af113397b7f5b666892cd3845de8af40af Mon Sep 17 00:00:00 2001 From: cogwheel0 <172976095+cogwheel0@users.noreply.github.com> Date: Thu, 27 Nov 2025 22:09:56 +0530 Subject: [PATCH] fix(tts): Improve speak completion handling to prevent race conditions --- lib/features/chat/services/text_to_speech_service.dart | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/features/chat/services/text_to_speech_service.dart b/lib/features/chat/services/text_to_speech_service.dart index 6225e55..831befc 100644 --- a/lib/features/chat/services/text_to_speech_service.dart +++ b/lib/features/chat/services/text_to_speech_service.dart @@ -88,7 +88,11 @@ class TextToSpeechService { _deviceEngineAvailable = false; try { await _ensureAndroidDefaultEngine(); - await _tts.awaitSpeakCompletion(false); + // Ensure speak() futures complete only after playback finishes. + // This avoids race conditions where completion callbacks fire + // early in release builds (especially on iOS), which can cause + // our voice-call pipeline to resume listening and cut off speech. + await _tts.awaitSpeakCompletion(true); await _tts.setVolume(volume); await _tts.setSpeechRate(speechRate); await _tts.setPitch(pitch);