From a8c08712900b49c18a9a2d8c4e70a1afbd58f71a Mon Sep 17 00:00:00 2001 From: cogwheel0 <172976095+cogwheel0@users.noreply.github.com> Date: Thu, 27 Nov 2025 22:01:19 +0530 Subject: [PATCH 1/2] feat(voice-input): conditionally check mic permissions based on STT mode --- .../chat/services/voice_input_service.dart | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/features/chat/services/voice_input_service.dart b/lib/features/chat/services/voice_input_service.dart index 892f4e5..40f1452 100644 --- a/lib/features/chat/services/voice_input_service.dart +++ b/lib/features/chat/services/voice_input_service.dart @@ -523,9 +523,18 @@ class VoiceInputService { /// Ensures initialization and microphone permission before starting. Future> beginListening() async { await initialize(); - final hasMic = await checkPermissions(); - if (!hasMic) { - throw Exception('Microphone permission not granted'); + // For on-device STT we preflight the microphone permission so we can + // fail fast with a clear error before starting any recognition. + // + // For server-only STT we skip the preflight check and let the VAD / + // recording pipeline request or validate permissions as needed. This + // avoids false negatives from the lightweight probe and prevents + // blocking server STT when the platform would otherwise allow it. + if (!prefersServerOnly) { + final hasMic = await checkPermissions(); + if (!hasMic) { + throw Exception('Microphone permission not granted'); + } } return await startListening(); } 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 2/2] 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);