SpeechToText class
An interface to device specific speech recognition services.
The general flow of a speech recognition session is as follows:
SpeechToText speech = SpeechToText();
bool isReady = await speech.initialize();
if ( isReady ) {
await speech.listen( resultListener: resultListener );
}
...
// At some point later
speech.stop();
Constructors
- SpeechToText()
-
factory
- SpeechToText.withMethodChannel()
Properties
- errorListener ↔ SpeechErrorListener?
-
getter/setter pair
- hasError → bool
-
True if an error has been received, see lastError for details
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
-
hasPermission
→ Future<
bool> -
Returns true if the user has already granted permission to access the
microphone, does not prompt the user.
no setter
- hasRecognized → bool
-
True if words have been recognized during the current listen call.
no setter
- isAvailable → bool
-
True if initialize succeeded
no setter
- isListening → bool
-
True if listen succeeded and stop or cancel has not been called.
no setter
- isNotListening → bool
-
no setter
- lastError → SpeechRecognitionError?
-
The last error received or null if none, see initialize to
register an optional listener to be notified of errors.
no setter
- lastRecognizedWords → String
-
The last set of recognized words received.
no setter
- lastSoundLevel → double
-
The last sound level received during a listen event.
no setter
- lastStatus → String
-
The last status update received, see initialize to register
an optional listener to be notified when this changes.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- statusListener ↔ SpeechStatusListener?
-
getter/setter pair
Methods
-
cancel(
) → Future< void> - Cancels the current listen for speech if active, does nothing if not.
-
initialize(
{SpeechErrorListener? onError, SpeechStatusListener? onStatus, dynamic debugLogging = false, Duration finalTimeout = defaultFinalTimeout, List< SpeechConfigOption> ? options}) → Future<bool> - Initialize speech recognition services, returns true if successful, false if failed.
-
listen(
{SpeechResultListener? onResult, Duration? listenFor, Duration? pauseFor, String? localeId, SpeechSoundLevelChange? onSoundLevelChange, dynamic cancelOnError = false, dynamic partialResults = true, dynamic onDevice = false, ListenMode listenMode = ListenMode.confirmation, dynamic sampleRate = 0}) → Future -
Starts a listening session for speech and converts it to text,
invoking the provided
onResult
method as words are recognized. -
locales(
) → Future< List< LocaleName> > - returns the list of speech locales available on the device or those supported by the speech recognizer on the device.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
stop(
) → Future< void> - Stops the current listen for speech if active, does nothing if not.
-
systemLocale(
) → Future< LocaleName?> - returns the locale that will be used if no localeId is passed to the listen method.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Properties
- androidAlwaysUseStop → SpeechConfigOption
-
on Android SDK 29 the recognizer stop method did not work properly so the
plugin destroys the recognizer instead. If this causes problems
this option overrides that behaviour and forces the plugin to use
the stop command instead, even on SDK 29.
final
- androidIntentLookup → SpeechConfigOption
-
Some Android builds do not properly define the default speech
recognition intent. This option forces a workaround to lookup the
intent by querying the intent manager.
final
- androidNoBluetooth → SpeechConfigOption
-
If your application does not need Bluetooth support on Android and
you'd rather not have to ask for Bluetooth permission pass this option
to disable Bluetooth support on Android.
final
- iosNoBluetooth → SpeechConfigOption
-
This option does nothing yet, may disable Bluetooth on iOS if there is
a need.
final
Constants
- defaultFinalTimeout → const Duration
- doneStatus → const String
- listeningStatus → const String
- listenMethod → const String
- notifyErrorMethod → const String
- notifyStatusMethod → const String
- notListeningStatus → const String
- soundLevelChangeMethod → const String
- textRecognitionMethod → const String