Merge pull request #191 from cogwheel0/voice-input-mic-permissions-stt-mode

voice-input-mic-permissions-stt-mode
This commit is contained in:
cogwheel
2025-11-27 22:21:39 +05:30
committed by GitHub
2 changed files with 17 additions and 4 deletions

View File

@@ -88,7 +88,11 @@ class TextToSpeechService {
_deviceEngineAvailable = false; _deviceEngineAvailable = false;
try { try {
await _ensureAndroidDefaultEngine(); 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.setVolume(volume);
await _tts.setSpeechRate(speechRate); await _tts.setSpeechRate(speechRate);
await _tts.setPitch(pitch); await _tts.setPitch(pitch);

View File

@@ -523,9 +523,18 @@ class VoiceInputService {
/// Ensures initialization and microphone permission before starting. /// Ensures initialization and microphone permission before starting.
Future<Stream<String>> beginListening() async { Future<Stream<String>> beginListening() async {
await initialize(); await initialize();
final hasMic = await checkPermissions(); // For on-device STT we preflight the microphone permission so we can
if (!hasMic) { // fail fast with a clear error before starting any recognition.
throw Exception('Microphone permission not granted'); //
// 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(); return await startListening();
} }