diff --git a/VoiceInk/Whisper/LibWhisper.swift b/VoiceInk/Whisper/LibWhisper.swift index e8ffb5b..ab96b99 100644 --- a/VoiceInk/Whisper/LibWhisper.swift +++ b/VoiceInk/Whisper/LibWhisper.swift @@ -104,19 +104,21 @@ actor WhisperContext { } static func createContext(path: String) async throws -> WhisperContext { + // Create the context in an isolated task return try await Task.detached { var params = whisper_context_default_params() #if targetEnvironment(simulator) params.use_gpu = false print("Running on the simulator, using CPU") #endif - let context = whisper_init_from_file_with_params(path, params) - if let context { - return WhisperContext(context: context) - } else { + + guard let contextPtr = whisper_init_from_file_with_params(path, params) else { print("Couldn't load model at \(path)") throw WhisperError.couldNotInitializeContext } + + // Create the actor instance directly in this task + return WhisperContext(context: contextPtr) }.value }