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
impl Recognizer
Sourcepub fn new(model: &Model, sample_rate: f32) -> Option<Self>
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.
Sourcepub fn new_with_speaker(
model: &Model,
sample_rate: f32,
speaker_model: &SpeakerModel,
) -> Option<Self>
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.
Sourcepub fn new_with_grammar(
model: &Model,
sample_rate: f32,
grammar: &[impl AsRef<str>],
) -> Option<Self>
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");
Sourcepub fn set_speaker_model(&mut self, speaker_model: &SpeakerModel)
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.
Sourcepub fn set_max_alternatives(&mut self, max_alternatives: u16)
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)
Sourcepub fn set_words(&mut self, enable: bool)
pub fn set_words(&mut self, enable: bool)
Enables or disables words with metadata in the output, represented as:
Sourcepub fn set_partial_words(&mut self, enable: bool)
pub fn set_partial_words(&mut self, enable: bool)
Like set_words
, but for PartialResult
.
Words will always be represented as Word
Sourcepub fn set_nlsml(&mut self, enable: bool)
pub fn set_nlsml(&mut self, enable: bool)
Enables or disables Natural Language Semantics Markup Language (NLSML) in the output
Sourcepub fn accept_waveform(
&mut self,
data: &[i16],
) -> Result<DecodingState, AcceptWaveformError>
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.
Sourcepub fn result(&mut self) -> CompleteResult<'_>
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.
Sourcepub fn partial_result(&mut self) -> PartialResult<'_>
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.
Sourcepub fn final_result(&mut self) -> CompleteResult<'_>
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