Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update whisper.cpp to 8e46ba8 #85

Merged
merged 10 commits into from
Oct 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ See [BUILDING.md](BUILDING.md) for instructions for building whisper-rs on Windo
## Troubleshooting

* Something other than Windows/macOS/Linux isn't working!
* I don't have a way to test this platforms, so I can't really help you.
* I don't have a way to test these platforms, so I can't really help you.
* If you can get it working, please open a PR with any changes to make it work and build instructions in BUILDING.md!
* I get a panic during binding generation build!
* You can attempt to fix it yourself, or you can set the `WHISPER_DONT_GENERATE_BINDINGS` environment variable.
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
18 changes: 4 additions & 14 deletions src/standalone.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//! Standalone functions that have no associated type.

use crate::WhisperToken;
use std::ffi::{c_int, CStr, CString};

/// Return the id of the specified language, returns -1 if not found
Expand Down Expand Up @@ -54,21 +53,12 @@ pub fn get_lang_str(id: i32) -> Option<&'static str> {
}
}

// task tokens
/// Get the ID of the translate task token.
/// Callback to control logging output: default behaviour is to print to stderr.
///
/// # C++ equivalent
/// `whisper_token whisper_token_translate ()`
pub fn token_translate() -> WhisperToken {
unsafe { whisper_rs_sys::whisper_token_translate() }
}

/// Get the ID of the transcribe task token.
///
/// # C++ equivalent
/// `whisper_token whisper_token_transcribe()`
pub fn token_transcribe() -> WhisperToken {
unsafe { whisper_rs_sys::whisper_token_transcribe() }
/// `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.
Expand Down
34 changes: 30 additions & 4 deletions src/whisper_ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,15 @@ impl WhisperContext {
unsafe { whisper_rs_sys::whisper_token_sot(self.ctx) }
}

/// Get the ID of the solm token.
///
/// # C++ equivalent
/// `whisper_token whisper_token_solm(struct whisper_context * ctx)`
#[inline]
pub fn token_solm(&self) -> WhisperToken {
unsafe { whisper_rs_sys::whisper_token_solm(self.ctx) }
}

/// Get the ID of the prev token.
///
/// # C++ equivalent
Expand All @@ -376,13 +385,13 @@ impl WhisperContext {
unsafe { whisper_rs_sys::whisper_token_prev(self.ctx) }
}

/// Get the ID of the solm token.
/// Get the ID of the nosp token.
///
/// # C++ equivalent
/// `whisper_token whisper_token_solm(struct whisper_context * ctx)`
/// `whisper_token whisper_token_nosp(struct whisper_context * ctx)`
#[inline]
pub fn token_solm(&self) -> WhisperToken {
unsafe { whisper_rs_sys::whisper_token_solm(self.ctx) }
pub fn token_nosp(&self) -> WhisperToken {
unsafe { whisper_rs_sys::whisper_token_nosp(self.ctx) }
}

/// Get the ID of the not token.
Expand Down Expand Up @@ -432,6 +441,23 @@ impl WhisperContext {
pub fn reset_timings(&self) {
unsafe { whisper_rs_sys::whisper_reset_timings(self.ctx) }
}

// task tokens
/// Get the ID of the translate task token.
///
/// # C++ equivalent
/// `whisper_token whisper_token_translate ()`
pub fn token_translate(&self) -> WhisperToken {
unsafe { whisper_rs_sys::whisper_token_translate(self.ctx) }
}

/// Get the ID of the transcribe task token.
///
/// # C++ equivalent
/// `whisper_token whisper_token_transcribe()`
pub fn token_transcribe(&self) -> WhisperToken {
unsafe { whisper_rs_sys::whisper_token_transcribe(self.ctx) }
}
}

impl Drop for WhisperContext {
Expand Down
44 changes: 44 additions & 0 deletions src/whisper_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,15 @@ impl<'a, 'b> FullParams<'a, 'b> {
self.fp.speed_up = speed_up;
}

/// # EXPERIMENTAL
///
/// Enables debug mode, such as dumping the log mel spectrogram.
///
/// Defaults to false.
pub fn set_debug_mode(&mut self, debug: bool) {
self.fp.debug_mode = debug;
}

/// # EXPERIMENTAL
///
/// Overwrite the audio context size. 0 = default.
Expand All @@ -216,6 +225,16 @@ impl<'a, 'b> FullParams<'a, 'b> {
self.fp.audio_ctx = audio_ctx;
}

/// # EXPERIMENTAL
///
/// Enable tinydiarize support.
/// Experimental speaker turn detection.
///
/// Defaults to false.
pub fn set_tdrz_enable(&mut self, tdrz_enable: bool) {
self.fp.tdrz_enable = tdrz_enable;
}

/// Set tokens to provide the model as initial input.
///
/// These tokens are prepended to any existing text content from a previous call.
Expand Down Expand Up @@ -485,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
Expand Down
2 changes: 1 addition & 1 deletion sys/whisper.cpp
Submodule whisper.cpp updated 135 files