9

I am working on an android application that uses the TextToSpeech functionality provided by google and have followed this example:

TTS Example from Google

I want to know with this line:

int result = mTts.setLanguage(Locale.US);
    if (result == TextToSpeech.LANG_MISSING_DATA ||
        result == TextToSpeech.LANG_NOT_SUPPORTED) {
        // Lanuage data is missing or the language is not supported.
    }

What can I do if the Language data is missing off the users device? The app will not continue if the data is not there? Is there a way to allow the user to get the language on their device? I have a test device that seems to not have any languages on it at all.

Charles
  • 50,943
  • 13
  • 104
  • 142
SamRowley
  • 3,435
  • 7
  • 48
  • 77

1 Answers1

15

From http://developer.android.com/resources/articles/tts.html:

// missing data, install it
            Intent installIntent = new Intent();
            installIntent.setAction(
                TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
            startActivity(installIntent);

No good way to know exactly what happens if the language they want simply doesn't exist at all, but....that is the recommended way of dealing with it.

Femi
  • 64,273
  • 8
  • 118
  • 148
  • 1
    URL has died. :( Try https://android-developers.googleblog.com/2009/09/introduction-to-text-to-speech-in.html?m=1 – Maarten Dec 12 '18 at 12:30
  • Yes, you can download the languages, but how to get them working as a new language downloaded and how can we choose that language as default? – Bay Jan 01 '21 at 18:05
  • No Activity found to handle Intent { act=android.speech.tts.engine.INSTALL_TTS_DATA } – linjiejun May 20 '22 at 02:53