KISHORE_ZE KISHORE_ZE - 1 year ago 547
Java Question

TextToSpeech setLanguage not working?

I am setting my TextToSpeech to use a particular language (English - UK), using the locale "en_GB". But it always uses my devices default language. Is there no way to set it programmatically? I have downloaded the files required for the language and when I change my TTS's default language to 'English - UK' it works but when the default is different the programmatic approach does not work. I have scoured the web to my best but am unable to resolve this issue.

String ttsEngine = "";
txt2Speech = new TextToSpeech(this, this, ttsEngine);
//Locale ttsLocale = new Locale("eng", "GBR");
txt2Speech.setLanguage(new Locale("en_GB"));

Tried several methods, but none are working.
Can I not set my TTS's language programmatically?

Thank You

EDIT: In response to 'A Honey Bustard'

Other Code:

public class MainActivity extends AppCompatActivity implements TextToSpeech.OnInitListener


public void onInit(int status) {
// TODO Auto-generated method stub


Also I'm calling
in my
, as soon as my
is initialized. Is that correct? Also I'm only calling it once. It is not required to call it every time right? Also I'm testing on a GS7

Answer Source

You need to set the language once the Text to Speech Engine has initialised correctly.

public void onInit(int status) {

    switch (status) {

        case SUCCESS:
        // Set the language here
        case ERROR:
         // Something went wrong. You can't set the language

That should do it.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download