'How to set kate voice for ios en-GB. in flutter - flutter_tts pub

How to set kate voice for ios en-GB.

I m doing the below code but it's doing Daniel's voice and I want to set kete voice for the same.

Future setLanguage({String value = 'en-US'}) async {
    var result = await objFlutterTts.isLanguageAvailable(value);
    print("setLanguageResult" + result.toString());
    await objFlutterTts.setLanguage(value);
    if (Platform.isIOS) {
      await objFlutterTts.setSharedInstance(true);
      List all = await objFlutterTts.getVoices;
      objFlutterTts.setVoice(all[6]);
      print(all);
      printLog("setVoice " + value.toLowerCase() + "-x-afx#female_1-local");
    }
}

enter image description here

https://github.com/dlutton/flutter_tts/issues/174



Solution 1:[1]

Voices are returned as objects. I had to convert to json and then decode from json:

import 'dart:convert';

List<Object?> voices = await flutterTts.getVoices;

List<String> jsonVoices = voices.map((e) => jsonEncode(e)).toList();

List availVoices = jsonVoices.map((e) => jsonDecode(e)).toList();

Then you can get the voice attributes - availVoices[0]['name'], availVoices[0]['locale']

You set the voice with:

flutterTts.setVoice({'name': availVoices[0]['name'], 'locale': availVoices[0]['locale']});

Solution 2:[2]

No need to encode/decode through Json like suggested by E G.

You can cast the result from getVoices :

List ttsVoices = await _textToSpeech.getVoices;
var availableVoices = ttsVoices.cast<Map>().map((e) => 
    e.cast<String,String>()).toList();

And select the one you need :

var selectedVoice = availableVoices.firstWhere((element) =>
    element['locale']!.contains('fr-FR'));

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 E G
Solution 2 Tanguy