From 4b45810dcacd2ce0dca59ec268e86dda2c51927b Mon Sep 17 00:00:00 2001 From: Niko Date: Fri, 6 Oct 2023 21:49:40 -0600 Subject: [PATCH] Update whisper.cpp --- src/lib.rs | 2 ++ src/standalone.rs | 8 ++++++++ src/whisper_params.rs | 25 +++++++++++++++++++++++++ sys/whisper.cpp | 2 +- 4 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 4d30fee..8c3ac3c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -24,3 +24,5 @@ pub type WhisperNewSegmentCallback = whisper_rs_sys::whisper_new_segment_callbac pub type WhisperStartEncoderCallback = whisper_rs_sys::whisper_encoder_begin_callback; pub type WhisperProgressCallback = whisper_rs_sys::whisper_progress_callback; pub type WhisperLogitsFilterCallback = whisper_rs_sys::whisper_logits_filter_callback; +pub type WhisperAbortCallback = whisper_rs_sys::whisper_abort_callback; +pub type WhisperLogCallback = whisper_rs_sys::whisper_log_callback; diff --git a/src/standalone.rs b/src/standalone.rs index ef7373a..4928785 100644 --- a/src/standalone.rs +++ b/src/standalone.rs @@ -53,6 +53,14 @@ pub fn get_lang_str(id: i32) -> Option<&'static str> { } } +/// Callback to control logging output: default behaviour is to print to stderr. +/// +/// # C++ equivalent +/// `void whisper_set_log_callback(whisper_log_callback callback);` +pub unsafe fn set_log_callback(callback: whisper_rs_sys::whisper_log_callback) { + unsafe { whisper_rs_sys::whisper_set_log_callback(callback) } +} + /// Print system information. /// /// # C++ equivalent diff --git a/src/whisper_params.rs b/src/whisper_params.rs index 68870f4..73e57be 100644 --- a/src/whisper_params.rs +++ b/src/whisper_params.rs @@ -504,6 +504,31 @@ impl<'a, 'b> FullParams<'a, 'b> { ) { self.fp.logits_filter_callback_user_data = user_data; } + + /// Set the callback that is called each time before ggml computation starts. + /// + /// Note that this callback has not been Rustified yet (and likely never will be, unless someone else feels the need to do so). + /// It is still a C callback. + /// + /// # Safety + /// Do not use this function unless you know what you are doing. + /// * Be careful not to mutate the state of the whisper_context pointer returned in the callback. + /// This could cause undefined behavior, as this violates the thread-safety guarantees of the underlying C library. + /// + /// Defaults to None. + pub unsafe fn set_abort_callback(&mut self, abort_callback: crate::WhisperAbortCallback) { + self.fp.abort_callback = abort_callback; + } + + /// Set the user data to be passed to the abort callback. + /// + /// # Safety + /// See the safety notes for `set_abort_callback`. + /// + /// Defaults to None. + pub unsafe fn set_abort_callback_user_data(&mut self, user_data: *mut std::ffi::c_void) { + self.fp.abort_callback_user_data = user_data; + } } // following implementations are safe diff --git a/sys/whisper.cpp b/sys/whisper.cpp index 54735be..91c0b23 160000 --- a/sys/whisper.cpp +++ b/sys/whisper.cpp @@ -1 +1 @@ -Subproject commit 54735be80f85fec2b08b09b44641b2698dbdef79 +Subproject commit 91c0b23384fc3725013c4b6d3b35c45ad92dea0a