Skip to main content

WhisperContext

Struct WhisperContext 

Source
pub struct WhisperContext { /* private fields */ }

Implementations§

Source§

impl WhisperContext

Source

pub fn new<P: AsRef<Path>>(model_path: P) -> Result<Self>

Source

pub fn new_from_buffer(buffer: &[u8]) -> Result<Self>

Source

pub fn is_multilingual(&self) -> bool

Source

pub fn n_vocab(&self) -> i32

Source

pub fn n_audio_ctx(&self) -> i32

Source

pub fn n_text_ctx(&self) -> i32

Source

pub fn n_len(&self) -> i32

Source§

impl WhisperContext

Source

pub async fn transcribe_async(&self, audio: Vec<f32>) -> Result<String>

Transcribe audio asynchronously using default parameters

Source

pub async fn transcribe_with_params_async( &self, audio: Vec<f32>, params: TranscriptionParams, ) -> Result<TranscriptionResult>

Transcribe audio asynchronously with custom parameters

Source

pub async fn create_state_async(&self) -> Result<WhisperState>

Create an async state for manual control

Source§

impl WhisperContext

Source

pub fn transcribe(&self, audio: &[f32]) -> Result<String>

Transcribe audio using default parameters

§Arguments
  • audio - Audio samples (must be 16kHz mono f32)
§Returns

The transcribed text as a string

§Example
let ctx = WhisperContext::new("model.bin")?;
let audio = vec![0.0f32; 16000]; // 1 second
let text = ctx.transcribe(&audio)?;
Source

pub fn transcribe_with_params( &self, audio: &[f32], params: TranscriptionParams, ) -> Result<TranscriptionResult>

Transcribe audio with custom parameters

§Arguments
  • audio - Audio samples (must be 16kHz mono f32)
  • params - Custom transcription parameters
§Returns

A TranscriptionResult containing the full text and individual segments

Source

pub fn transcribe_with_full_params( &self, audio: &[f32], params: FullParams, ) -> Result<TranscriptionResult>

Transcribe audio with full control over parameters

§Arguments
  • audio - Audio samples (must be 16kHz mono f32)
  • params - Full parameter configuration
§Returns

A TranscriptionResult containing the full text and individual segments

Source

pub fn create_state(&self) -> Result<WhisperState>

Create a new state for manual transcription control

This allows you to reuse a state for multiple transcriptions, which can be more efficient than creating a new state each time.

Source

pub fn transcribe_with_params_enhanced( &self, audio: &[f32], params: TranscriptionParams, ) -> Result<TranscriptionResult>

Enhanced transcription with custom parameters and temperature fallback

This method provides quality-based retry with multiple temperatures if the initial transcription doesn’t meet quality thresholds.

§Arguments
  • audio - Audio samples (must be 16kHz mono f32)
  • params - Custom transcription parameters
§Returns

A TranscriptionResult containing the full text and individual segments

§Example
let ctx = WhisperContext::new("model.bin")?;
let params = TranscriptionParams::builder()
    .language("en")
    .build();
let audio = vec![0.0f32; 16000];
let result = ctx.transcribe_with_params_enhanced(&audio, params)?;
Source

pub fn transcribe_with_full_params_enhanced( &self, audio: &[f32], params: FullParams, ) -> Result<TranscriptionResult>

Enhanced transcription with full parameters and temperature fallback

This method provides quality-based retry with multiple temperatures if the initial transcription doesn’t meet quality thresholds.

§Arguments
  • audio - Audio samples (must be 16kHz mono f32)
  • params - Full parameter configuration
§Returns

A TranscriptionResult containing the full text and individual segments

Trait Implementations§

Source§

impl Clone for WhisperContext

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.