pub struct Model(/* private fields */);
Expand description
A trained Coqui STT model.
Implementations§
Source§impl Model
impl Model
Sourcepub fn new_from_buffer<'a>(buffer: impl AsRef<&'a [u8]>) -> Result<Self>
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.
Sourcepub unsafe fn into_inner(self) -> *mut ModelState
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.
Sourcepub const unsafe fn from_model_state(state: *mut ModelState) -> Self
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.
Sourcepub fn enable_external_scorer(
&mut self,
scorer_path: impl Into<String>,
) -> Result<()>
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.
Sourcepub fn enable_external_scorer_from_buffer(
&mut self,
buffer: impl AsRef<[u8]>,
) -> Result<()>
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.
Sourcepub fn disable_external_scorer(&mut self) -> Result<()>
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.
Sourcepub fn clear_hot_words(&mut self) -> Result<()>
pub fn clear_hot_words(&mut self) -> Result<()>
Sourcepub fn get_sample_rate(&self) -> i32
pub fn get_sample_rate(&self) -> i32
Return the sample rate expected by a model in Hz.
Sourcepub fn speech_to_text(&mut self, buffer: &[i16]) -> Result<String>
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.
Sourcepub fn speech_to_text_with_metadata(
&mut self,
buffer: &[i16],
num_results: u32,
) -> Result<Metadata>
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
.