rename WhisperInnerContext

This commit is contained in:
jiahua 2024-04-25 16:00:36 +08:00
parent 5eef5afd5e
commit 6e04f76e41
4 changed files with 19 additions and 19 deletions

View file

@ -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};

View file

@ -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

View file

@ -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<WhisperContext>,
ctx: Arc<WhisperInnerContext>,
}
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<Self, WhisperError> {
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<Self, WhisperError> {
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<Self, WhisperError> {
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<Self, WhisperError> {
let ctx = WhisperContext::new_from_buffer(buffer)?;
let ctx = WhisperInnerContext::new_from_buffer(buffer)?;
Ok(Self::wrap(ctx))
}

View file

@ -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<WhisperContext>,
ctx: Arc<WhisperInnerContext>,
ptr: *mut whisper_rs_sys::whisper_state,
}
@ -24,7 +24,7 @@ impl Drop for WhisperState {
impl WhisperState {
pub(crate) fn new(
ctx: Arc<WhisperContext>,
ctx: Arc<WhisperInnerContext>,
ptr: *mut whisper_rs_sys::whisper_state,
) -> Self {
Self {