fix(tts): Improve speak completion handling to prevent race conditions

This commit is contained in:
cogwheel0
2025-11-27 22:09:56 +05:30
parent a8c0871290
commit ff0c42af11

View File

@@ -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);