Flutter TTS (Text to Speech) - Is it possible & how to get language code for iOS voices?

3,242

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.

Share:
3,242
Gene Bo
Author by

Gene Bo

                          ★ ☆ ★ ☆ ★ ☆ ★ ☆ ★ ☆ ★ ☆ ★           ~ best dev quote; Words to code by ~          If it seems too complicated, it probably is                                   ★ ☆ ★ ☆ ★ ☆ ★ ☆ ★ ☆ ★ ☆ ★ SO mcve: Minimal, Complete, and Verifiable Example Handy aliases Placed in ~/.bashrc alias a="alias | more" alias ag="a | grep $1" alias c=clear alias h=history alias t=touch alias td="touch *" alias l="ls -al" alias ll="ls -alt" alias pd="pushd " alias vib="vi ~/.bashrc" alias sob="source ~/.bashrc" # git alias hg=hg1 alias gc=gc alias gs="git status ." alias gst="git stash save " alias gsl="git stash list" alias gstp="git stash pop" alias gf="git fetch" alias gb="git branch" alias gu="git config --get remote.origin.url" alias g="gs" alias grh="git reset HEAD " alias gl="git log" alias gpl="git pull" alias gpo="git pull origin" alias gpoh="gpo HEAD" alias gps="git push" alias gph="git push origin HEAD" alias ga='git add' alias gd='git diff' alias gco='git checkout ' alias gcod='gco develop ; git pull origin develop; gpl' #alias gcod='git checkout develop' alias gm='git mv' alias gr='git rm' # removes local repo branches that have already been merged on server alias clgb="git branch --merged develop | grep -v \"\* develop\" | xargs -n 1 git branch -d" # adb alias ks="adb kill-server" alias devices="adb devices" alias adbt="adb shell input text " alias adbk="adb shell input keyevent" alias adbkt="adbk 61" #tab alias adbke="adbk 66" #enter key function hg1 () { history | grep $1 } function gc () { git commit -m "$*" } Checklist for DataBinding with List Adapter: * 1. Add <layout> tag to the list item xml to get the Binding class * 2. Define instance member in ViewHolder for binding * 3. Define constructor that : takes the binding, sets click listener, calls .executePendingBindings() * 4. In onCreateViewHolder(): * A) instantiate binding via : DataBindingUtil.inflate(..) * B) return ViewHolder using : constructor(binding) * * 5. Access the binding in onBindViewHolder(); - to set ViewModel and otherwise access the list item layout * . .

Updated on December 21, 2022

Comments

  • Gene Bo
    Gene Bo over 1 year

    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?