Fixed switft example.

pull/494/head
Sandro Hanea 2 years ago
parent 2be35dd32b
commit ff00f01adb

@ -7,12 +7,15 @@ enum WhisperError: Error {
// Meet Whisper C++ constraint: Don't access from more than one thread at a time. // Meet Whisper C++ constraint: Don't access from more than one thread at a time.
actor WhisperContext { actor WhisperContext {
private var context: OpaquePointer private var context: OpaquePointer
private var state: OpaquePointer
init(context: OpaquePointer) { init(context: OpaquePointer) {
self.context = context self.context = context
self.state = whisper_init_state(context)
} }
deinit { deinit {
whisper_free_state(state)
whisper_free(context) whisper_free(context)
} }
@ -37,10 +40,10 @@ actor WhisperContext {
whisper_reset_timings(context) whisper_reset_timings(context)
print("About to run whisper_full") print("About to run whisper_full")
samples.withUnsafeBufferPointer { samples in 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") print("Failed to run the model")
} else { } else {
whisper_print_timings(context) whisper_print_timings(context, state)
} }
} }
} }
@ -48,8 +51,8 @@ actor WhisperContext {
func getTranscription() -> String { func getTranscription() -> String {
var transcription = "" var transcription = ""
for i in 0..<whisper_full_n_segments(context) { for i in 0..<whisper_full_n_segments(state) {
transcription += String.init(cString: whisper_full_get_segment_text(context, i)) transcription += String.init(cString: whisper_full_get_segment_text(state, i))
} }
return transcription return transcription
} }

Loading…
Cancel
Save