ttsGetAvailableVoices method
Get the list of available TTS voices on the platform.
On the platforms that implement TTS — Android, iOS, Web — this does not throw merely because TTS is not enabled. Android and iOS return an empty list. Web queries the browser's speech synthesis directly and may return voices whether or not TTS is enabled. To populate a voice picker before enabling TTS, use ttsGetSystemVoices.
Implementation
@override
Future<List<ReaderTTSVoice>> ttsGetAvailableVoices() async {
final voicesStr = await methodChannel.invokeMethod<List<dynamic>>(
'ttsGetAvailableVoices',
);
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;
}