// Meet Whisper C++ constraint: Don't access from more than one thread at a time.
actor WhisperContext {
private var context: OpaquePointer
-
+
init(context: OpaquePointer) {
self.context = context
}
-
+
deinit {
whisper_free(context)
}
-
+
func fullTranscribe(samples: [Float]) {
// Leave 2 processors free (i.e. the high-efficiency cores).
let maxThreads = max(1, min(8, cpuCount() - 2))
var params = whisper_full_default_params(WHISPER_SAMPLING_GREEDY)
"en".withCString { en in
// Adapted from whisper.objc
- params.print_realtime = true
- params.print_progress = false
+ params.print_realtime = true
+ params.print_progress = false
params.print_timestamps = true
- params.print_special = false
- params.translate = false
- params.language = en
- params.n_threads = Int32(maxThreads)
- params.offset_ms = 0
- params.no_context = true
- params.single_segment = false
-
+ params.print_special = false
+ params.translate = false
+ params.language = en
+ params.n_threads = Int32(maxThreads)
+ params.offset_ms = 0
+ params.no_context = true
+ params.single_segment = false
+
whisper_reset_timings(context)
print("About to run whisper_full")
samples.withUnsafeBufferPointer { samples in
}
}
}
-
+
func getTranscription() -> String {
var transcription = ""
for i in 0..<whisper_full_n_segments(context) {
}
return transcription
}
-
+
static func createContext(path: String) throws -> WhisperContext {
var params = whisper_context_default_params()
#if targetEnvironment(simulator)