refactor(state): create_state from whisper context wrapper
This commit is contained in:
parent
74e83185bf
commit
9d978add9d
3 changed files with 40 additions and 19 deletions
|
|
@ -10,7 +10,7 @@ use std::ffi::{c_int, CStr, CString};
|
|||
/// then run a full transcription with [WhisperState::full].
|
||||
#[derive(Debug)]
|
||||
pub struct WhisperContext {
|
||||
ctx: *mut whisper_rs_sys::whisper_context,
|
||||
pub(crate) ctx: *mut whisper_rs_sys::whisper_context,
|
||||
}
|
||||
|
||||
impl WhisperContext {
|
||||
|
|
@ -114,24 +114,6 @@ impl WhisperContext {
|
|||
}
|
||||
}
|
||||
|
||||
// we don't implement `whisper_init()` here since i have zero clue what `whisper_model_loader` does
|
||||
|
||||
/// Create a new state object, ready for use.
|
||||
///
|
||||
/// # Returns
|
||||
/// Ok(WhisperState) on success, Err(WhisperError) on failure.
|
||||
///
|
||||
/// # C++ equivalent
|
||||
/// `struct whisper_state * whisper_init_state(struct whisper_context * ctx);`
|
||||
pub fn create_state(&self) -> Result<WhisperState, WhisperError> {
|
||||
let state = unsafe { whisper_rs_sys::whisper_init_state(self.ctx) };
|
||||
if state.is_null() {
|
||||
Err(WhisperError::InitError)
|
||||
} else {
|
||||
// SAFETY: this is known to be a valid pointer to a `whisper_state` struct
|
||||
Ok(WhisperState::new(self.ctx, state))
|
||||
}
|
||||
}
|
||||
|
||||
/// Convert the provided text into tokens.
|
||||
///
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue