From 797d3da7bafb588d235f8420598333f3bab85d86 Mon Sep 17 00:00:00 2001 From: Beingpax Date: Thu, 6 Mar 2025 17:37:23 +0545 Subject: [PATCH] Fix sendable warning in whispercontext --- VoiceInk/Whisper/LibWhisper.swift | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) 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 }