Struct Recognizer

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

The main object which processes data. Takes audio as input and returns decoded information as words, confidences, times, and other metadata.

Implementations§

Source§

impl Recognizer

Source

pub fn new(model: &Model, sample_rate: f32) -> Option<Self>

Creates the recognizer object. Returns None if a problem occured.

The recognizers process the speech and return text using shared model data.

  • model - Model containing static data for recognizer. Model can be shared across recognizers, even running in different threads.

  • sample_rate - The sample rate of the audio you going to feed into the recognizer. Make sure this rate matches the audio content, it is a common issue causing accuracy problems.

Source

pub fn new_with_speaker( model: &Model, sample_rate: f32, speaker_model: &SpeakerModel, ) -> Option<Self>

Creates the recognizer object with speaker recognition. Returns None if a problem occured

With the speaker recognition mode the recognizer not just recognize text but also return speaker vectors one can use for speaker identification

  • model - Model containing the data for recognizer. Model can be shared across recognizers, even running in different threads.

  • sample_rate - The sample rate of the audio you going to feed into the recognizer. Make sure this rate matches the audio content, it is a common issue causing accuracy problems.

  • spk_model - Speaker model for speaker identification.

Source

pub fn new_with_grammar( model: &Model, sample_rate: f32, grammar: &[impl AsRef<str>], ) -> Option<Self>

Creates the recognizer object with that only recognizes certain words. Returns None if a problem occured.

Sometimes when you want to improve recognition accuracy and when you don’t need to recognize large vocabulary you can specify a list of phrases to recognize. This will improve recognizer speed and accuracy but might return [unk] if user said something different.

Only recognizers with lookahead models support this type of quick configuration. Precompiled HCLG graph models are not supported.

  • model - Model containing the data for recognizer. Model can be shared across recognizers, even running in different threads.

  • sample_rate - The sample rate of the audio you going to feed into the recognizer. Make sure this rate matches the audio content, it is a common issue causing accuracy problems.

  • grammar - The list of phrases to recognize.

§Examples
let model = Model::new("/path/to/model").expect("Could not create a model");
let recognizer = Recognizer::new_with_grammar(
    &model,
    16000.0,
    &["one two three four five", "[unk]"],
)
.expect("Could not create a recognizer");
Source

pub fn set_speaker_model(&mut self, speaker_model: &SpeakerModel)

Adds speaker model to already initialized recognizer

Can add speaker recognition model to already created recognizer. Helps to initialize speaker recognition for grammar-based recognizer.

Source

pub fn set_max_alternatives(&mut self, max_alternatives: u16)

Configures recognizer to output n-best results in result and final_result

The returned value from those methods will be a CompleteResult::Single if max_alternatives is 0, and CompleteResult::Multiple otherwise.

  • max_alternatives - Maximum alternatives to return (may be fewer) (default: 0)
Source

pub fn set_words(&mut self, enable: bool)

Enables or disables words with metadata in the output, represented as:

Source

pub fn set_partial_words(&mut self, enable: bool)

Like set_words, but for PartialResult.

Words will always be represented as Word

Source

pub fn set_nlsml(&mut self, enable: bool)

Enables or disables Natural Language Semantics Markup Language (NLSML) in the output

Source

pub fn accept_waveform( &mut self, data: &[i16], ) -> Result<DecodingState, AcceptWaveformError>

Accept and process new chunk of voice data.

  • data - Audio data in PCM 16-bit mono format.

Returns a DecodingState, which represents the state of the decodification after this chunk of data has been processed.

Source

pub fn result(&mut self) -> CompleteResult<'_>

Returns speech recognition result, waiting for silence (see DecodingState::Finalized) to give a result.

The returned value will be a CompleteResult::Single if set_max_alternatives was passed a 0 (default), and CompleteResult::Multiple otherwise.

If words are enabled (see set_words), it also returns metadata abut the words.

Source

pub fn partial_result(&mut self) -> PartialResult<'_>

Returns partial speech recognition, which is not yet finalized and may change after processing more data.

If words are enabled (see set_partial_words), it also returns metadata abut the words.

Source

pub fn final_result(&mut self) -> CompleteResult<'_>

Returns speech recognition result. Like result but it does not wait for silence and it flushes the data so everything is processed

Source

pub fn reset(&mut self)

Resets current results and data so the recognition can continue from scratch

Trait Implementations§

Source§

impl Drop for Recognizer

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Send for Recognizer

Source§

impl Sync for Recognizer

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.