diff --git a/src/lib.rs b/src/lib.rs index d9b75cd..eca465b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -22,7 +22,7 @@ pub use standalone::*; #[cfg(any(feature = "whisper-cpp-log", feature = "whisper-cpp-tracing"))] use std::sync::Once; pub use utilities::*; -pub use whisper_ctx::WhisperContext; +use whisper_ctx::WhisperInnerContext; pub use whisper_ctx_wrapper::WhisperContextWrapper; pub use whisper_ctx::WhisperContextParameters; pub use whisper_grammar::{WhisperGrammarElement, WhisperGrammarElementType}; diff --git a/src/whisper_ctx.rs b/src/whisper_ctx.rs index dbb7448..d7415ab 100644 --- a/src/whisper_ctx.rs +++ b/src/whisper_ctx.rs @@ -5,15 +5,15 @@ use std::ffi::{c_int, CStr, CString}; /// Safe Rust wrapper around a Whisper context. /// -/// You likely want to create this with [WhisperContext::new_with_params], -/// create a state with [WhisperContext::create_state], +/// You likely want to create this with [WhisperInnerContext::new_with_params], +/// create a state with [WhisperInnerContext::create_state], /// then run a full transcription with [WhisperState::full]. #[derive(Debug)] -pub struct WhisperContext { +pub struct WhisperInnerContext { pub(crate) ctx: *mut whisper_rs_sys::whisper_context, } -impl WhisperContext { +impl WhisperInnerContext { /// Create a new WhisperContext from a file, with parameters. /// /// # Arguments @@ -516,7 +516,7 @@ impl WhisperContext { } } -impl Drop for WhisperContext { +impl Drop for WhisperInnerContext { #[inline] fn drop(&mut self) { unsafe { whisper_rs_sys::whisper_free(self.ctx) }; @@ -525,8 +525,8 @@ impl Drop for WhisperContext { // following implementations are safe // see https://github.com/ggerganov/whisper.cpp/issues/32#issuecomment-1272790388 -unsafe impl Send for WhisperContext {} -unsafe impl Sync for WhisperContext {} +unsafe impl Send for WhisperInnerContext {} +unsafe impl Sync for WhisperInnerContext {} pub struct WhisperContextParameters { /// Use GPU if available. @@ -570,7 +570,7 @@ mod test_with_tiny_model { #[test] fn test_tokenize_round_trip() { - let ctx = WhisperContext::new(MODEL_PATH).expect("Download the ggml-tiny.en model using 'sys/whisper.cpp/models/download-ggml-model.sh tiny.en'"); + let ctx = WhisperInnerContext::new(MODEL_PATH).expect("Download the ggml-tiny.en model using 'sys/whisper.cpp/models/download-ggml-model.sh tiny.en'"); let text_in = " And so my fellow Americans, ask not what your country can do for you, ask what you can do for your country."; let tokens = ctx.tokenize(text_in, 1024).unwrap(); let text_out = tokens diff --git a/src/whisper_ctx_wrapper.rs b/src/whisper_ctx_wrapper.rs index 57e1b77..51bcdac 100644 --- a/src/whisper_ctx_wrapper.rs +++ b/src/whisper_ctx_wrapper.rs @@ -1,14 +1,14 @@ use std::ffi::{c_int, CStr}; use std::sync::Arc; -use crate::{WhisperContext, WhisperContextParameters, WhisperError, WhisperState, WhisperToken}; +use crate::{WhisperInnerContext, WhisperContextParameters, WhisperError, WhisperState, WhisperToken}; pub struct WhisperContextWrapper { - ctx: Arc, + ctx: Arc, } impl WhisperContextWrapper { - fn wrap(ctx: WhisperContext) -> Self { + fn wrap(ctx: WhisperInnerContext) -> Self { Self { ctx: Arc::new(ctx), } @@ -29,7 +29,7 @@ impl WhisperContextWrapper { path: &str, parameters: WhisperContextParameters, ) -> Result { - let ctx = WhisperContext::new_with_params(path, parameters)?; + let ctx = WhisperInnerContext::new_with_params(path, parameters)?; Ok(Self::wrap(ctx)) } @@ -47,7 +47,7 @@ impl WhisperContextWrapper { buffer: &[u8], parameters: WhisperContextParameters, ) -> Result { - let ctx = WhisperContext::new_from_buffer_with_params(buffer, parameters)?; + let ctx = WhisperInnerContext::new_from_buffer_with_params(buffer, parameters)?; Ok(Self::wrap(ctx)) } @@ -63,7 +63,7 @@ impl WhisperContextWrapper { /// `struct whisper_context * whisper_init_from_file_no_state(const char * path_model)` #[deprecated = "Use `new_with_params` instead"] pub fn new(path: &str) -> Result { - let ctx = WhisperContext::new(path)?; + let ctx = WhisperInnerContext::new(path)?; Ok(Self::wrap(ctx)) } @@ -79,7 +79,7 @@ impl WhisperContextWrapper { /// `struct whisper_context * whisper_init_from_buffer_no_state(void * buffer, size_t buffer_size)` #[deprecated = "Use `new_from_buffer_with_params` instead"] pub fn new_from_buffer(buffer: &[u8]) -> Result { - let ctx = WhisperContext::new_from_buffer(buffer)?; + let ctx = WhisperInnerContext::new_from_buffer(buffer)?; Ok(Self::wrap(ctx)) } diff --git a/src/whisper_state.rs b/src/whisper_state.rs index 99f2ff1..025c109 100644 --- a/src/whisper_state.rs +++ b/src/whisper_state.rs @@ -1,12 +1,12 @@ use std::ffi::{c_int, CStr}; use std::sync::Arc; -use crate::{FullParams, WhisperContext, WhisperError, WhisperToken, WhisperTokenData}; +use crate::{FullParams, WhisperInnerContext, WhisperError, WhisperToken, WhisperTokenData}; /// Rustified pointer to a Whisper state. #[derive(Debug)] pub struct WhisperState { - ctx: Arc, + ctx: Arc, ptr: *mut whisper_rs_sys::whisper_state, } @@ -24,7 +24,7 @@ impl Drop for WhisperState { impl WhisperState { pub(crate) fn new( - ctx: Arc, + ctx: Arc, ptr: *mut whisper_rs_sys::whisper_state, ) -> Self { Self {