From 73ac365ed41ec982be42128b560e4db13a7d6eb7 Mon Sep 17 00:00:00 2001 From: Beingpax Date: Thu, 5 Jun 2025 12:46:26 +0545 Subject: [PATCH] Fix: ESC fully cancels recording and transcription. --- VoiceInk/Whisper/WhisperState+UI.swift | 1 - VoiceInk/Whisper/WhisperState.swift | 19 ++++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/VoiceInk/Whisper/WhisperState+UI.swift b/VoiceInk/Whisper/WhisperState+UI.swift index 1356389..22a20f6 100644 --- a/VoiceInk/Whisper/WhisperState+UI.swift +++ b/VoiceInk/Whisper/WhisperState+UI.swift @@ -75,7 +75,6 @@ extension WhisperState { isTranscribing = false canTranscribe = true isMiniRecorderVisible = false - shouldCancelRecording = false } diff --git a/VoiceInk/Whisper/WhisperState.swift b/VoiceInk/Whisper/WhisperState.swift index 7851bb1..bfbfaf6 100644 --- a/VoiceInk/Whisper/WhisperState.swift +++ b/VoiceInk/Whisper/WhisperState.swift @@ -126,6 +126,14 @@ class WhisperState: NSObject, ObservableObject, AVAudioRecorderDelegate { if let recordedFile { if !shouldCancelRecording { await transcribeAudio(recordedFile) + } else { + logger.info("🛑 Transcription and paste aborted in toggleRecord due to shouldCancelRecording flag.") + await MainActor.run { + isProcessing = false + isTranscribing = false + canTranscribe = true + } + await cleanupModelResources() } } else { logger.error("❌ No recorded file found after stopping recording") @@ -238,7 +246,16 @@ class WhisperState: NSObject, ObservableObject, AVAudioRecorderDelegate { } private func transcribeAudio(_ url: URL) async { - if shouldCancelRecording { return } + if shouldCancelRecording { + logger.info("🎤 Transcription and paste aborted at the beginning of transcribeAudio due to shouldCancelRecording flag.") + await MainActor.run { + isProcessing = false + isTranscribing = false + canTranscribe = true + } + await cleanupModelResources() + return + } await MainActor.run { isProcessing = true isTranscribing = true