whisper.objc : disable timestamps for real-time transcription

This commit is contained in:
Georgi Gerganov 2023-12-08 13:43:37 +02:00
parent 29511d33c7
commit 9521ba6801
No known key found for this signature in database
GPG Key ID: 449E073F9DC10735
2 changed files with 16 additions and 15 deletions

View File

@ -206,6 +206,7 @@ void AudioInputCallback(void * inUserData,
params.offset_ms = 0; params.offset_ms = 0;
params.no_context = true; params.no_context = true;
params.single_segment = self->stateInp.isRealtime; params.single_segment = self->stateInp.isRealtime;
params.no_timestamps = params.single_segment;
CFTimeInterval startTime = CACurrentMediaTime(); CFTimeInterval startTime = CACurrentMediaTime();

View File

@ -8,15 +8,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
init(context: OpaquePointer) { init(context: OpaquePointer) {
self.context = context self.context = context
} }
deinit { deinit {
whisper_free(context) whisper_free(context)
} }
func fullTranscribe(samples: [Float]) { func fullTranscribe(samples: [Float]) {
// Leave 2 processors free (i.e. the high-efficiency cores). // Leave 2 processors free (i.e. the high-efficiency cores).
let maxThreads = max(1, min(8, cpuCount() - 2)) let maxThreads = max(1, min(8, cpuCount() - 2))
@ -24,17 +24,17 @@ actor WhisperContext {
var params = whisper_full_default_params(WHISPER_SAMPLING_GREEDY) var params = whisper_full_default_params(WHISPER_SAMPLING_GREEDY)
"en".withCString { en in "en".withCString { en in
// Adapted from whisper.objc // Adapted from whisper.objc
params.print_realtime = true params.print_realtime = true
params.print_progress = false params.print_progress = false
params.print_timestamps = true params.print_timestamps = true
params.print_special = false params.print_special = false
params.translate = false params.translate = false
params.language = en params.language = en
params.n_threads = Int32(maxThreads) params.n_threads = Int32(maxThreads)
params.offset_ms = 0 params.offset_ms = 0
params.no_context = true params.no_context = true
params.single_segment = false params.single_segment = false
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
@ -46,7 +46,7 @@ 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(context) {
@ -54,7 +54,7 @@ actor WhisperContext {
} }
return transcription return transcription
} }
static func createContext(path: String) throws -> WhisperContext { static func createContext(path: String) throws -> WhisperContext {
var params = whisper_context_default_params() var params = whisper_context_default_params()
#if targetEnvironment(simulator) #if targetEnvironment(simulator)