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.
-
changePauseFor(
Duration pauseFor) → void - Call this while listen is active to change the pauseFor duration. This will restart the timer for the new duration. It is useful for allowing a long first pause then dynamically shortening it once the user starts speaking.
-
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, SpeechListenOptions? listenOptions}) → 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
- webDoNotAggregate → SpeechConfigOption
-
On some mobile web browsers, notably Chrome on Android, the speech
results behave differently. The default behaviour is to aggregate
separate phrases into a single result and return it. On
Chrome Android that approach creates duplicates so this option
can be used to disable the aggregation and return just the expected
result. You will need to test the user agent of the browser to
decide whether to use this option.
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