coqui_stt

Struct Model

Source
pub struct Model(/* private fields */);
Expand description

A trained Coqui STT model.

Implementations§

Source§

impl Model

Source

pub fn new(model_path: impl Into<String>) -> Result<Self>

Create a new model.

§Errors

Returns an error if the model path is invalid, or for other reasons.

Source

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

Create a new model from a memory buffer.

§Errors

Returns an error if the model is invalid, or for other reasons.

Source

pub unsafe fn into_inner(self) -> *mut ModelState

Take this model, and return the inner model state.

This is useful if the safe API does not provide something you need.

§Safety

Once this is called, the memory management of the model is no longer handled for you.

You must not forget to call STT_FreeModel once you are done with the pointer to dispose of the model properly.

Source

pub const unsafe fn from_model_state(state: *mut ModelState) -> Self

Create a new model from an existing model state.

§Safety

You must ensure state is a valid model state.

Source

pub fn enable_external_scorer( &mut self, scorer_path: impl Into<String>, ) -> Result<()>

Enable an external scorer for this model.

§Errors

Returns an error if the scorer_path/file pointed to is invalid in some way.

Source

pub fn enable_external_scorer_from_buffer( &mut self, buffer: impl AsRef<[u8]>, ) -> Result<()>

Enable an external scorer for this model, loaded from a buffer in memory.

§Errors

Returns an error if the scorer in memory is invalid in some way.

Source

pub fn disable_external_scorer(&mut self) -> Result<()>

Disable an external scorer that was previously set up with enable_external_scorer.

§Errors

Returns an error if an error happened while disabling the scorer.

Source

pub fn add_hot_word( &mut self, word: impl Into<String>, boost: f32, ) -> Result<()>

Add a hot-word and its boost.

Words that don’t occur in the scorer (e.g. proper nouns), or strings that contain spaces won’t be taken into account.

§Errors

Passes through any errors from the C library. See enum Error.

Source

pub fn erase_hot_word(&mut self, word: impl Into<String>) -> Result<()>

Remove entry for a hot-word from the hot-words map.

§Errors

Passes through any errors from the C library. See enum Error.

Additionally, if the input word contains a NUL character anywhere in it, returns an error.

Source

pub fn clear_hot_words(&mut self) -> Result<()>

Removes all elements from the hot-words map.

§Errors

Passes through any errors from the C library. See enum Error.

Source

pub fn set_scorer_alpha_beta(&mut self, alpha: f32, beta: f32) -> Result<()>

Set hyperparameters alpha and beta of the external scorer.

alpha is the alpha hyperparameter of the decoder. Language model weight.

beta is the beta hyperparameter of the decoder. Word insertion weight.

§Errors

Passes through any errors from the C library. See enum Error.

Source

pub fn get_sample_rate(&self) -> i32

Return the sample rate expected by a model in Hz.

Source

pub fn speech_to_text(&mut self, buffer: &[i16]) -> Result<String>

Use the Coqui STT model to convert speech to text.

buffer should be a 16-bit, mono, raw audio signal at the appropriate sample rate, matching what the model was trained on. The required sample rate can be obtained from get_sample_rate.

§Errors

Passes through any errors from the C library. See enum Error.

Additionally, if the returned string is not valid UTF-8, this function returns an error.

Source

pub fn speech_to_text_with_metadata( &mut self, buffer: &[i16], num_results: u32, ) -> Result<Metadata>

Use the Coqui STT model to convert speech to text and output results including metadata.

buffer should be a 16-bit, mono, raw audio signal at the appropriate sample rate, matching what the model was trained on. The required sample rate can be obtained from get_sample_rate.

num_results is the maximum number of possible transcriptions to return. Note that it is not guaranteed this many will be returned at minimum, but there will never be more than this number at maximum.

§Errors

Passes through any errors from the C library. See enum Error.

Source

pub fn as_streaming(&mut self) -> Result<Stream<'_>>

Convert this model into one used for streaming inference states.

Note that this requires exclusive access to the model, so it is not possible to use the same model for multiple streams concurrently.

§Errors

Passes through any errors from the C library. See enum Error.

Trait Implementations§

Source§

impl Drop for Model

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Send for Model

Source§

impl Sync for Model

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> 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, 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.