initialize method
- SpeechErrorListener? onError,
- SpeechStatusListener? onStatus,
- dynamic debugLogging = false,
- Duration finalTimeout = _defaultFinalTimeout,
- List<
SpeechConfigOption> ? options,
Initialize speech recognition services, returns true if successful, false if failed.
This method must be called before any other speech functions. If this method returns false no further SpeechToText methods should be used. Should only be called once if successful but does protect itself if called repeatedly. False usually means that the user has denied permission to use speech. The usual option in that case is to give them instructions on how to open system settings and grant permission.
onError
is an optional listener for errors like
timeout, or failure of the device speech recognition.
onStatus
is an optional listener for status changes from
listening to not listening.
debugLogging
controls whether there is detailed logging from the underlying
plugins. It is off by default, usually only useful for troubleshooting issues
with a paritcular OS version or device, fairly verbose
finalTimeout
a duration to wait for a final result from the device
speech recognition service. If no final result is received within this
time the last partial result is returned as final. This defaults to
two seconds. A duration of fifty milliseconds or less disables the
check and final results will only be returned from the device.
options
pass platform specific configuration options to the
platform specific implementation.
Implementation
Future<bool> initialize(
{SpeechErrorListener? onError,
SpeechStatusListener? onStatus,
debugLogging = false,
Duration finalTimeout = _defaultFinalTimeout,
List<SpeechConfigOption>? options}) async {
if (_initWorked) {
return Future.value(_initWorked);
}
_finalTimeout = finalTimeout;
if (finalTimeout <= _minFinalTimeout) {}
errorListener = onError;
statusListener = onStatus;
SpeechToTextPlatform.instance.onTextRecognition = _onTextRecognition;
SpeechToTextPlatform.instance.onError = _onNotifyError;
SpeechToTextPlatform.instance.onStatus = _onNotifyStatus;
SpeechToTextPlatform.instance.onSoundLevel = _onSoundLevelChange;
_initWorked = await SpeechToTextPlatform.instance
.initialize(debugLogging: debugLogging, options: options);
return _initWorked;
}