3

I am working on a Flutter app that uses the TTS library.

The available voice objects returned from flutterTts.getVoices() is device/OS specific.

In the app, for a given TTS language, I would like to give users the option to select from a set of available voices for that language.

Functional Objective: Solved for Android

When running Flutter TTS on Android, the list of voices returned are strings that indicate which language-code that a voice corresponds to. For example:

  • for language-code en-US
  • there is: en-US-language, en-us-x-sfg#male_1-local

This built-in meta data allows to create a Map<String, List<String>> with the following type of key/value pairs:

  • key: en-us
  • value: ['en-US-language', 'en-us-x-sfg#male_1-local']

Then having this map, when user selects say English from the list of available languages, there can be a drop down list like so:

Map<String, String> labelToVoiceMap = {
   'Voice1' : 'en-US-language',
   'Voice2' : 'en-us-x-sfg#male_1-local'
}

Question

When running Flutter TTS on iOS, the list of voices returned is just human names.

  • For example: Aaron, Fred

Is there a way in Flutter to determine what the associated language is for a particular voice returned from the flutterTts object?

Here is a post - unrelated to Flutter - describing the voice objects on an iOS device, that shows there is a field/property for language/locale code: How to get a list of ALL voices on iOS 9?

eg: [AVSpeechSynthesisVoice 0x28266fb40] Language: en-US, Name: Fred, Quality: Default [com.apple.speech.synthesis.voice.Fred]

Option 1: .. any way to get at that in Flutter?

~~ ~~~~~ ~~~~~ ~~~~~ ~~~~~ ~~~

Option 2: Alternatively - for a given name on iOS (eg, 'Fred'), if that voice is available on the current device, is there some official listing that guarantees what the associated language code will be for that voice name?

Gene Bo
  • 11,284
  • 8
  • 90
  • 137
  • This seems like one of those questions where, if you include *why* you need this functionality, someone might be able to suggest a less problematic path to take. – Nerdy Bunz Jun 08 '20 at 23:04
  • Fair enough - on the Android side I use this meta data to organize/group the voices in a `Map` by language code. This way I have a hierarchy I can work with. – Gene Bo Jun 08 '20 at 23:26
  • I realize my initial reply to your comment is a bit vague. You make a good point, I have updated the question. Thank you for the suggestion, it improves the post – Gene Bo Jun 14 '20 at 23:27

1 Answers1

4

To do exactly what you're trying to do, what really needs to happen is Flutter TTS needs to add a new method: getVoicesForLocale(String locale).

Or you or someone would need to write a separate Flutter package that does this one task.

But this would be extremely complicated to do, or at least to do well. For example, you have presumably only handled one Android TTS engine so far.

You're probably not going to like this answer, but your best bet for predictable cross platform TTS is to use a single cloud service, probably Google cloud tts.

To answer your last question, I'm pretty darn sure each IOS voice has a unique name and will always have the same associated language... so assuming you really do have the Android side handled, you could hard code the relationships in your app, but you'd have to handle the IOS side differently in that you can't just reflect all installed voices to the user like on Android because what if Apple adds new voices? You would have to filter them to known voices.

Nerdy Bunz
  • 6,040
  • 10
  • 41
  • 100
  • I was thinking the same thing, for a given iOS TTS voice - I figured for Apple in particular, it is something standardized *company/product*-wide. That post I shared in my question has a list of some of the voice mappings - but would be nice to find if there is an official list from Apple. Or perhaps it is something they choose not to share .. ? – Gene Bo Jun 19 '20 at 16:35
  • For now though, I suppose it's one of those things I can assume to be true going fwd, that a given Apple-voice name will always have the same associated language *(once I can find it!)* across 100% iOS devices .. until I find out myself or get end-user feedback, that it is not the case. – Gene Bo Jun 19 '20 at 16:35