listen method
- String? localeId,
- @deprecated dynamic partialResults = true,
- @deprecated dynamic onDevice = false,
- @deprecated int listenMode = 0,
- @deprecated dynamic sampleRate = 0,
- SpeechListenOptions? options,
Starts a listening session for speech and converts it to text.
Cannot be used until a successful initialize call. There is a time limit on listening imposed by both Android and iOS. The time depends on the device, network, etc. Android is usually quite short, especially if there is no active speech event detected, on the order of ten seconds or so.
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.
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.
sampleRate
optional for compatibility with certain iOS devices, some devices
crash with sampleRate != device's supported sampleRate
, try 44100 if seeing
crashes
Implementation
@override
Future<bool> listen(
{String? localeId,
@deprecated partialResults = true,
@deprecated onDevice = false,
@deprecated int listenMode = 0,
@deprecated sampleRate = 0,
SpeechListenOptions? options}) async {
if (null == _webSpeech) return false;
_webSpeech!.onResult.listen((speechEvent) => _onResult(speechEvent));
_webSpeech!.interimResults = options?.partialResults ?? partialResults;
_webSpeech!.continuous = options?.partialResults ?? partialResults;
if (null != localeId) {
_webSpeech!.lang = localeId;
}
_doneSent = false;
_resultSent = false;
_webSpeech!.start();
return true;
}