From ff00f01adb1be30b9ca6a48986dbb9741ca3f1e3 Mon Sep 17 00:00:00 2001 From: Sandro Hanea Date: Mon, 13 Feb 2023 16:40:22 +0100 Subject: [PATCH] Fixed switft example. --- .../whisper.cpp.swift/LibWhisper.swift | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/examples/whisper.swiftui/whisper.cpp.swift/LibWhisper.swift b/examples/whisper.swiftui/whisper.cpp.swift/LibWhisper.swift index e9645b3..68b46c4 100644 --- a/examples/whisper.swiftui/whisper.cpp.swift/LibWhisper.swift +++ b/examples/whisper.swiftui/whisper.cpp.swift/LibWhisper.swift @@ -7,12 +7,15 @@ enum WhisperError: Error { // Meet Whisper C++ constraint: Don't access from more than one thread at a time. actor WhisperContext { private var context: OpaquePointer - + private var state: OpaquePointer + init(context: OpaquePointer) { self.context = context + self.state = whisper_init_state(context) } deinit { + whisper_free_state(state) whisper_free(context) } @@ -37,10 +40,10 @@ actor WhisperContext { whisper_reset_timings(context) print("About to run whisper_full") samples.withUnsafeBufferPointer { samples in - if (whisper_full(context, params, samples.baseAddress, Int32(samples.count)) != 0) { + if (whisper_full_with_state(context, state, params, samples.baseAddress, Int32(samples.count)) != 0) { print("Failed to run the model") } else { - whisper_print_timings(context) + whisper_print_timings(context, state) } } } @@ -48,8 +51,8 @@ actor WhisperContext { func getTranscription() -> String { var transcription = "" - for i in 0..