From 32dab33fc4b0b3e6ba6ec8e0b552f10362034f8c Mon Sep 17 00:00:00 2001 From: cogwheel0 <172976095+cogwheel0@users.noreply.github.com> Date: Thu, 27 Nov 2025 20:18:42 +0530 Subject: [PATCH] feat(voice-input): Refactor voice input availability check logic --- .../chat/services/voice_input_service.dart | 33 ++++++++++++------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/lib/features/chat/services/voice_input_service.dart b/lib/features/chat/services/voice_input_service.dart index 55b852a..892f4e5 100644 --- a/lib/features/chat/services/voice_input_service.dart +++ b/lib/features/chat/services/voice_input_service.dart @@ -998,19 +998,28 @@ final voiceInputServiceProvider = Provider((ref) { Future voiceInputAvailable(Ref ref) async { final service = ref.watch(voiceInputServiceProvider); if (!service.isSupportedPlatform) return false; - final initialized = await service.initialize(); - if (!initialized) return false; - switch (service.preference) { - case SttPreference.deviceOnly: - if (service.hasLocalStt) return true; - if (!service.hasServerStt) return false; - break; - case SttPreference.serverOnly: - return service.hasServerStt; + + // IMPORTANT: + // Do NOT initialize STT or request microphone/speech permissions here. + // This provider is watched by the chat UI during app startup; calling + // initialize() or checkPermissions() would trigger permission dialogs + // before the user explicitly opts into voice features. + // + // Instead, treat voice input as "available" based on platform support + // and configuration only. The actual initialization + permission flow + // happens on-demand via VoiceInputService.beginListening(). + + // If the user prefers server-only STT, only expose voice input when a + // server STT backend is configured. + if (service.preference == SttPreference.serverOnly) { + return service.hasServerStt; } - final hasPermission = await service.checkPermissions(); - if (!hasPermission) return false; - return service.isAvailable; + + // For device-only (or mixed) preferences, assume voice input is + // potentially available on supported platforms. Any missing + // permissions or lack of local STT support will be handled when + // beginListening() is called. + return true; } final voiceInputStreamProvider = StreamProvider((ref) {