Pranav
Pranav

Reputation: 826

Android Text to Speech voice to indian accent

I have developed an android application which provides text to speech functionality. I have used below code syntax to set indian accent :

public void onInit(int status) {
    if (status == TextToSpeech.SUCCESS) {
        int result;
        Locale locale = new Locale("en","IN");
        if (textToSpeech.isLanguageAvailable(locale) == TextToSpeech.LANG_AVAILABLE) {
            result = textToSpeech.setLanguage(locale);
        } else {
            result = textToSpeech.setLanguage(Locale.ENGLISH);
        }
        if (result == TextToSpeech.LANG_MISSING_DATA
                || result == TextToSpeech.LANG_NOT_SUPPORTED) {
            Log.e("TTS", "This Language is not supported");
        } 

    } else {

        Log.e("TTS", "Initilization Failed!");
    }
}

But when i access this functionality, it still speak in US accent. Any help would be much appreciated.

Upvotes: 2

Views: 3366

Answers (4)

Aayush Mathur
Aayush Mathur

Reputation: 97

I Tried doing this , which worked for me

tts.setLanguage(new Locale("hin", "IND"));

Otherwise, you can also select Google's Text To Speech Engine while initialising the TextToSpeech Object and after that, you can just select Hindi as the language.

 tts = new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() {
    //code for TTS
  tts.setLanguage(new Locale("hin"));
      }, "com.google.android.tts");//specifying which engine to use; if this is not available, it uses default

In this the string "com.google.android.tts" is the package name of the Google's Text To Speech Engine.

I hope this works for you too! Cheers!

Upvotes: 2

Subrata
Subrata

Reputation: 182

The code below gives you the list of available languages for the TextToSpeech

TextToSpeech textToSpeech;
Log.e(TAG, "Languages: "+textToSpeech.getAvailableLanguages());

which would be :

[ko_KR, ru_RU, zh_TW, hu_HU, th_TH, nb_NO, da_DK, tr_TR, et_EE, bs, sw, vi_VN, en_US, sv_SE, su_ID, bn_BD, sk, el_GR, hi_IN, fi_FI, km_KH, bn_IN, fr_FR, uk_UA, en_AU, nl_NL, fr_CA, sr, pt_BR, si_LK, de_DE, ku, cs_CZ, pl_PL, sk_SK, fil_PH, it_IT, ne_NP, hr, zh_CN, es_ES, cy, ja_JP, sq, yue_HK, en_IN, es_US, jv_ID, la, in_ID, ro_RO, ca, ta, en_GB]

Trying out hi_IN instead of en_IN helped in my case, where I got the Indian accent. Code below:

Locale locale = new Locale("hi_IN");
textToSpeech.setLanguage(locale);

Hope this helps more people in the future.

Upvotes: 0

Deepak Gautam
Deepak Gautam

Reputation: 193

you should use

textToSpeech.setLanguage(new Locale("en", "IN"));

Upvotes: 1

Tung Tran
Tung Tran

Reputation: 2955

mLanguage = new Locale(language_codes);
tts = new TextToSpeech(mContext, new TextToSpeech.OnInitListener() {
        @Override
        public void onInit(int status) {
            if (status != TextToSpeech.ERROR) {
                int result = tts.setLanguage(mLanguage);
                if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) {
                    Log.e("Text2SpeechWidget", result + " is not supported");
                }
            }
        }
    });

And I use language from https://www.w3schools.com/tags/ref_language_codes.asp

Hope to help you.

Upvotes: 1

Related Questions