From c681c614636ebb0d7eb71da4ade360f243171e74 Mon Sep 17 00:00:00 2001 From: Beingpax Date: Tue, 25 Feb 2025 21:17:48 +0545 Subject: [PATCH] Fix: Add delays in audio engine cleanup to prevent HALC_ProxyIOContext overload errors --- VoiceInk/WhisperState.swift | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/VoiceInk/WhisperState.swift b/VoiceInk/WhisperState.swift index e54ea52..2bb7f0d 100644 --- a/VoiceInk/WhisperState.swift +++ b/VoiceInk/WhisperState.swift @@ -742,6 +742,9 @@ class WhisperState: NSObject, ObservableObject, AVAudioRecorderDelegate { // Only cleanup temporary files, not the permanent recordings audioEngine.stopAudioEngine() + // Add a small delay to allow audio system to complete its operations + try? await Task.sleep(nanoseconds: 100_000_000) // 100ms delay + // Release whisper resources if not needed if !isRecording && !isProcessing { await whisperContext?.releaseResources() @@ -785,6 +788,8 @@ class WhisperState: NSObject, ObservableObject, AVAudioRecorderDelegate { // 5. Finally clean up resources logger.info("Cleaning up resources") + // Add a small delay before cleanup to prevent audio overload + try? await Task.sleep(nanoseconds: 150_000_000) // 150ms delay await cleanupResources() logger.info("Mini recorder dismissal completed") }