listen method
Start listening for new events, set partialResults
to true to receive interim
recognition results.
partialResults
if true the listen reports results as they are recognized,
when false only final results are reported. Defaults to true.
onDevice
if true the listen attempts to recognize locally with speech never
leaving the device. If it cannot do this the listen attempt will fail. This is
usually only needed for sensitive content where privacy or security is a concern.
soundLevel
set to true to be notified on changes to the input sound level
on the microphone.
listenFor
sets the maximum duration that it will listen for, after
that it automatically stops the listen for you.
pauseFor
sets the maximum duration of a pause in speech with no words
detected, after that it automatically stops the listen for you.
localeId
is an optional locale that can be used to listen in a language
other than the current system default. See locales to find the list of
supported languages for listening.
Call this only after a successful initialize call
Implementation
void listen(
{bool partialResults = true,
onDevice = false,
bool soundLevel = false,
Duration? listenFor,
Duration? pauseFor,
String? localeId}) {
_lastLevel = 0;
_lastResult = null;
if (soundLevel) {
_speechToText.listen(
partialResults: partialResults,
onDevice: onDevice,
listenFor: listenFor,
pauseFor: pauseFor,
cancelOnError: true,
onResult: _onListenResult,
onSoundLevelChange: _onSoundLevelChange,
localeId: localeId);
} else {
_speechToText.listen(
partialResults: partialResults,
onDevice: onDevice,
listenFor: listenFor,
pauseFor: pauseFor,
cancelOnError: true,
onResult: _onListenResult,
localeId: localeId);
}
}