[英]Android Text to Speech voice to indian accent
我開發了一個提供文本到語音功能的 android 應用程序。 我使用以下代碼語法來設置印度口音:
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!");
}
}
但是當我訪問這個功能時,它仍然用美國口音說話。 任何幫助將非常感激。
我試過這樣做,這對我有用
tts.setLanguage(new Locale("hin", "IND"));
否則,您還可以在初始化 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
在此字符串“com.google.android.tts”是 Google 的 Text To Speech Engine 的包名稱。
我希望這對你也有用! 干杯!
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");
}
}
}
});
我使用來自https://www.w3schools.com/tags/ref_language_codes.asp的語言
希望能幫到你。
你應該使用
textToSpeech.setLanguage(new Locale("en", "IN"));
下面的代碼為您提供了 TextToSpeech 的可用語言列表
TextToSpeech textToSpeech;
Log.e(TAG, "Languages: "+textToSpeech.getAvailableLanguages());
這將是:
[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]
嘗試使用 hi_IN而不是en_IN對我的情況有所幫助,我得到了印度口音。 代碼如下:
Locale locale = new Locale("hi_IN");
textToSpeech.setLanguage(locale);
希望這能在未來幫助更多的人。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.