elwis
elwis

Reputation: 1405

android, text to speech

I'm playing with text to speech to make my testapp a little more fun. It works in the emulator but not on my phone since my default locale isn't english.

However, the texts are english so the tts should of course use english. As far as I know I can implement an autoninstall, something like

    public void onInit(int status) {

    if (status == TextToSpeech.SUCCESS) {
        // Set preferred language to US english.

        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.
            Log.e(TAG, "Language is not available.");
        } else {

            // The TTS engine has been successfully initialized.
            speak();
        }
    } else {
        // missing data, install it
        Intent installIntent = new Intent();
        installIntent.setAction(
            TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
        startActivity(installIntent);
    }
}

But, do I want to? Does installing locales take a lot of space? Does it mess up something else?

regards

Upvotes: 2

Views: 2745

Answers (3)

A-Droid Tech
A-Droid Tech

Reputation: 2321

Android allows you convert your text into voice. Not only you can convert it but it also allows you to speak text in variety of different languages. Android provides TextToSpeech class for this purpose. For more detail please follow this tutorial :-

http://a-droidtech.blogspot.in/2015/06/android-text-to-speech-tutorial-android.html

Upvotes: 0

RCB
RCB

Reputation: 560

I would only try the install in the case where "LANG_MISSING_DATA" not for "LANG_NOT_SUPPORTED". Since it starts another activity and the user can choose whether they download it or not, I wouldn't worry too much about it taking space. No, it shouldn't mess anything up.

Upvotes: 0

gregm
gregm

Reputation: 12149

You should execute this:

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

when you get LANG_MISSING_DATA

Upvotes: 3

Related Questions