rename WhisperInnerContext
This commit is contained in:
parent
5eef5afd5e
commit
6e04f76e41
4 changed files with 19 additions and 19 deletions
|
|
@ -22,7 +22,7 @@ pub use standalone::*;
|
||||||
#[cfg(any(feature = "whisper-cpp-log", feature = "whisper-cpp-tracing"))]
|
#[cfg(any(feature = "whisper-cpp-log", feature = "whisper-cpp-tracing"))]
|
||||||
use std::sync::Once;
|
use std::sync::Once;
|
||||||
pub use utilities::*;
|
pub use utilities::*;
|
||||||
pub use whisper_ctx::WhisperContext;
|
use whisper_ctx::WhisperInnerContext;
|
||||||
pub use whisper_ctx_wrapper::WhisperContextWrapper;
|
pub use whisper_ctx_wrapper::WhisperContextWrapper;
|
||||||
pub use whisper_ctx::WhisperContextParameters;
|
pub use whisper_ctx::WhisperContextParameters;
|
||||||
pub use whisper_grammar::{WhisperGrammarElement, WhisperGrammarElementType};
|
pub use whisper_grammar::{WhisperGrammarElement, WhisperGrammarElementType};
|
||||||
|
|
|
||||||
|
|
@ -5,15 +5,15 @@ use std::ffi::{c_int, CStr, CString};
|
||||||
|
|
||||||
/// Safe Rust wrapper around a Whisper context.
|
/// Safe Rust wrapper around a Whisper context.
|
||||||
///
|
///
|
||||||
/// You likely want to create this with [WhisperContext::new_with_params],
|
/// You likely want to create this with [WhisperInnerContext::new_with_params],
|
||||||
/// create a state with [WhisperContext::create_state],
|
/// create a state with [WhisperInnerContext::create_state],
|
||||||
/// then run a full transcription with [WhisperState::full].
|
/// then run a full transcription with [WhisperState::full].
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct WhisperContext {
|
pub struct WhisperInnerContext {
|
||||||
pub(crate) ctx: *mut whisper_rs_sys::whisper_context,
|
pub(crate) ctx: *mut whisper_rs_sys::whisper_context,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WhisperContext {
|
impl WhisperInnerContext {
|
||||||
/// Create a new WhisperContext from a file, with parameters.
|
/// Create a new WhisperContext from a file, with parameters.
|
||||||
///
|
///
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
|
|
@ -516,7 +516,7 @@ impl WhisperContext {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Drop for WhisperContext {
|
impl Drop for WhisperInnerContext {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
unsafe { whisper_rs_sys::whisper_free(self.ctx) };
|
unsafe { whisper_rs_sys::whisper_free(self.ctx) };
|
||||||
|
|
@ -525,8 +525,8 @@ impl Drop for WhisperContext {
|
||||||
|
|
||||||
// following implementations are safe
|
// following implementations are safe
|
||||||
// see https://github.com/ggerganov/whisper.cpp/issues/32#issuecomment-1272790388
|
// see https://github.com/ggerganov/whisper.cpp/issues/32#issuecomment-1272790388
|
||||||
unsafe impl Send for WhisperContext {}
|
unsafe impl Send for WhisperInnerContext {}
|
||||||
unsafe impl Sync for WhisperContext {}
|
unsafe impl Sync for WhisperInnerContext {}
|
||||||
|
|
||||||
pub struct WhisperContextParameters {
|
pub struct WhisperContextParameters {
|
||||||
/// Use GPU if available.
|
/// Use GPU if available.
|
||||||
|
|
@ -570,7 +570,7 @@ mod test_with_tiny_model {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_tokenize_round_trip() {
|
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 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 tokens = ctx.tokenize(text_in, 1024).unwrap();
|
||||||
let text_out = tokens
|
let text_out = tokens
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,14 @@
|
||||||
use std::ffi::{c_int, CStr};
|
use std::ffi::{c_int, CStr};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use crate::{WhisperContext, WhisperContextParameters, WhisperError, WhisperState, WhisperToken};
|
use crate::{WhisperInnerContext, WhisperContextParameters, WhisperError, WhisperState, WhisperToken};
|
||||||
|
|
||||||
pub struct WhisperContextWrapper {
|
pub struct WhisperContextWrapper {
|
||||||
ctx: Arc<WhisperContext>,
|
ctx: Arc<WhisperInnerContext>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WhisperContextWrapper {
|
impl WhisperContextWrapper {
|
||||||
fn wrap(ctx: WhisperContext) -> Self {
|
fn wrap(ctx: WhisperInnerContext) -> Self {
|
||||||
Self {
|
Self {
|
||||||
ctx: Arc::new(ctx),
|
ctx: Arc::new(ctx),
|
||||||
}
|
}
|
||||||
|
|
@ -29,7 +29,7 @@ impl WhisperContextWrapper {
|
||||||
path: &str,
|
path: &str,
|
||||||
parameters: WhisperContextParameters,
|
parameters: WhisperContextParameters,
|
||||||
) -> Result<Self, WhisperError> {
|
) -> Result<Self, WhisperError> {
|
||||||
let ctx = WhisperContext::new_with_params(path, parameters)?;
|
let ctx = WhisperInnerContext::new_with_params(path, parameters)?;
|
||||||
Ok(Self::wrap(ctx))
|
Ok(Self::wrap(ctx))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -47,7 +47,7 @@ impl WhisperContextWrapper {
|
||||||
buffer: &[u8],
|
buffer: &[u8],
|
||||||
parameters: WhisperContextParameters,
|
parameters: WhisperContextParameters,
|
||||||
) -> Result<Self, WhisperError> {
|
) -> 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))
|
Ok(Self::wrap(ctx))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -63,7 +63,7 @@ impl WhisperContextWrapper {
|
||||||
/// `struct whisper_context * whisper_init_from_file_no_state(const char * path_model)`
|
/// `struct whisper_context * whisper_init_from_file_no_state(const char * path_model)`
|
||||||
#[deprecated = "Use `new_with_params` instead"]
|
#[deprecated = "Use `new_with_params` instead"]
|
||||||
pub fn new(path: &str) -> Result<Self, WhisperError> {
|
pub fn new(path: &str) -> Result<Self, WhisperError> {
|
||||||
let ctx = WhisperContext::new(path)?;
|
let ctx = WhisperInnerContext::new(path)?;
|
||||||
Ok(Self::wrap(ctx))
|
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)`
|
/// `struct whisper_context * whisper_init_from_buffer_no_state(void * buffer, size_t buffer_size)`
|
||||||
#[deprecated = "Use `new_from_buffer_with_params` instead"]
|
#[deprecated = "Use `new_from_buffer_with_params` instead"]
|
||||||
pub fn new_from_buffer(buffer: &[u8]) -> Result<Self, WhisperError> {
|
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))
|
Ok(Self::wrap(ctx))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,12 @@
|
||||||
use std::ffi::{c_int, CStr};
|
use std::ffi::{c_int, CStr};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use crate::{FullParams, WhisperContext, WhisperError, WhisperToken, WhisperTokenData};
|
use crate::{FullParams, WhisperInnerContext, WhisperError, WhisperToken, WhisperTokenData};
|
||||||
|
|
||||||
/// Rustified pointer to a Whisper state.
|
/// Rustified pointer to a Whisper state.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct WhisperState {
|
pub struct WhisperState {
|
||||||
ctx: Arc<WhisperContext>,
|
ctx: Arc<WhisperInnerContext>,
|
||||||
ptr: *mut whisper_rs_sys::whisper_state,
|
ptr: *mut whisper_rs_sys::whisper_state,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -24,7 +24,7 @@ impl Drop for WhisperState {
|
||||||
|
|
||||||
impl WhisperState {
|
impl WhisperState {
|
||||||
pub(crate) fn new(
|
pub(crate) fn new(
|
||||||
ctx: Arc<WhisperContext>,
|
ctx: Arc<WhisperInnerContext>,
|
||||||
ptr: *mut whisper_rs_sys::whisper_state,
|
ptr: *mut whisper_rs_sys::whisper_state,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue