listen method

  1. @override
Future<bool> listen({
  1. String? localeId,
  2. @deprecated dynamic partialResults = true,
  3. @deprecated dynamic onDevice = false,
  4. @deprecated int listenMode = 0,
  5. @deprecated dynamic sampleRate = 0,
  6. SpeechListenOptions? options,
})
override

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 {
  Map<String, dynamic> listenParams = {
    "partialResults": options?.partialResults ?? partialResults,
    "onDevice": options?.onDevice ?? onDevice,
    "listenMode": options?.listenMode.index ?? listenMode,
    "sampleRate": options?.sampleRate ?? sampleRate,
    "enableHaptics": options?.enableHapticFeedback ?? false,
    "autoPunctuation": options?.autoPunctuation ?? false,
  };
  if (null != localeId) {
    listenParams["localeId"] = localeId;
  }
  return await _channel.invokeMethod<bool>('listen', listenParams) ?? false;
}