ttsGetSystemVoices method

  1. @override
Future<List<ReaderTTSVoice>> ttsGetSystemVoices()
override

Get the list of available TTS voices from the OS.

On the platforms that implement TTS — Android, iOS, Web — this is independent of the TTS session and reports the device's voices whether or not TTS is enabled. Prefer this for voice pickers shown before reading aloud starts; see ttsGetAvailableVoices for its per-platform behavior.

Implementation

@override
Future<List<ReaderTTSVoice>> ttsGetSystemVoices() async {
  final voicesStr = await methodChannel.invokeMethod<List<dynamic>>(
    'ttsGetSystemVoices',
  );
  final voices =
      voicesStr
          ?.whereType<String>()
          .map<Map<String, dynamic>>(
            (str) => json.decode(str) as Map<String, dynamic>,
          )
          .map<ReaderTTSVoice>((map) => ReaderTTSVoice.fromJsonMap(map))
          .toList() ??
      <ReaderTTSVoice>[];
  return voices;
}