I'm working on a text-to-speech implementation of a flashcard program. Text in different languages should be read out. In order to do this properly the user has to select the language of the text to read (will be stored and used later without question).
Is there a possibility of getting the available TTS languages on an Android system? If not, is there a possibility of getting all availably locales on the system?
I guess, I got it: getAvailableLocales()
and tts.isLocaleAvailable(locale)
Someone else has done the hard work, at http://kaviddiss.com/2012/08/12/android-text-to-speech-languages/
To save you time, here's their code extract
TextToSpeech tts = ... // let's assume tts is already inited at this point: Locale[] locales = Locale.getAvailableLocales(); List<Locale> localeList = new ArrayList<Locale>(); for (Locale locale : locales) { int res = tts.isLanguageAvailable(locale); if (res == TextToSpeech.LANG_COUNTRY_AVAILABLE) { localeList.add(locale); } } // at this point the localeList object will contain // all available languages for Text to Speech
The results depend on which TTS engine has been selected. For instance, one of my phones includes both the Pico-TTS and Google-text-to-speech engines.
Q-Smart (Vietnamese Phone with Google TTS as selected engine)
D/SpeakRepeatedly( 3979): Engine Google Text-to-speech Engine:com.google.android.tts D/SpeakRepeatedly( 3979): Engine Pico TTS:com.svox.pico D/SpeakRepeatedly( 3979): German (Germany):German:de_DE D/SpeakRepeatedly( 3979): English (United Kingdom):English:en_GB D/SpeakRepeatedly( 3979): English (United States):English:en_US D/SpeakRepeatedly( 3979): English (United States,Computer):English:en_US_POSIX D/SpeakRepeatedly( 3979): Spanish (Spain):Spanish:es_ES D/SpeakRepeatedly( 3979): French (France):French:fr_FR D/SpeakRepeatedly( 3979): Italian (Italy):Italian:it_IT D/SpeakRepeatedly( 3979): Portuguese (Brazil):Portuguese:pt_BR D/SpeakRepeatedly( 3979): Portuguese (Portugal):Portuguese:pt_PT
And with Pico selected
D/SpeakRepeatedly( 4837): Engine Google Text-to-speech Engine:com.google.android.tts D/SpeakRepeatedly( 4837): Engine Pico TTS:com.svox.pico D/SpeakRepeatedly( 4837): German (Germany):German:de_DE D/SpeakRepeatedly( 4837): English (United Kingdom):English:en_GB D/SpeakRepeatedly( 4837): English (United States):English:en_US D/SpeakRepeatedly( 4837): English (United States,Computer):English:en_US_POSIX D/SpeakRepeatedly( 4837): Spanish (Spain):Spanish:es_ES D/SpeakRepeatedly( 4837): French (France):French:fr_FR D/SpeakRepeatedly( 4837): Italian (Italy):Italian:it_IT
Note: Portuguese isn’t listed in the TTS Settings UI. When I select Portuguese programmatically in my app it speaks with a Portuguese accent! FWIW here's my code to select Portuguese (it accepts both Brazilian and Portuguese locales).
if (locale.getDisplayName().startsWith("Portuguese")) { Log.i(SPEAK_REPEATEDLY, "Setting Locale to: " + locale.toString()); tts.setLanguage(locale); } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With