Fix: ESC fully cancels recording and transcription.

This commit is contained in:
Beingpax 2025-06-05 12:46:26 +05:45
parent 3bbd93e578
commit 73ac365ed4
2 changed files with 18 additions and 2 deletions

View File

@ -75,7 +75,6 @@ extension WhisperState {
isTranscribing = false
canTranscribe = true
isMiniRecorderVisible = false
shouldCancelRecording = false
}

View File

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