简体   繁体   English

Android Text to Speech 语音到印度口音

[英]Android Text to Speech voice to indian accent

I have developed an android application which provides text to speech functionality.我开发了一个提供文本到语音功能的 android 应用程序。 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.任何帮助将非常感激。

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.否则,您还可以在初始化 TextToSpeech 对象时选择 Google 的 Text To Speech Engine,之后,您只需选择印地语作为语言。

 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.在此字符串“com.google.android.tts”是 Google 的 Text To Speech Engine 的包名称。

I hope this works for you too!我希望这对你也有用! Cheers!干杯!

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我使用来自https://www.w3schools.com/tags/ref_language_codes.asp的语言

Hope to help you.希望能帮到你。

you should use你应该使用

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

The code below gives you the list of available languages for the TextToSpeech下面的代码为您提供了 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] [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.尝试使用 hi_IN而不是en_IN对我的情况有所帮助,我得到了印度口音。 Code below:代码如下:

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

Hope this helps more people in the future.希望这能在未来帮助更多的人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM