在android中以编程方式将印地语设置为TextToSpeech语言

m2xkgtsf  于 2023-11-15  发布在  Android
关注(0)|答案(4)|浏览(168)

无法将印地语设置为文本转语音的语音语言,即使我的移动的TTS引擎完全支持印地语文本转语音

if(t1.isLanguageAvailable(new Locale("hi_IN"))==TextToSpeech.LANG_AVAILABLE)
            t1.setLanguage(new Locale ("hi_IN"));
        else
            Toast.makeText(getApplicationContext(), "Sorry! Text To Speech failed...", Toast.LENGTH_LONG).show();

字符串

2uluyalo

2uluyalo1#

首先,作为测试,在Android文本到语音设置中将文本到语音引擎设置为印地语。无需对代码进行任何更改,它应该可以成功地使用印地语。如果没有,请检查日志输出,看看是否有问题。
接下来,你的代码依赖于isBoundageAvailable()返回TextToSpeech.LANG_AVAILABLE,如果它没有,你将不会尝试设置Locale。还有许多其他可能的响应。检查下面两个case switch语句的日志输出。

final Locale loc = new Locale("hin", "IND");

    // switch(tts.isLanguageAvailable(loc)){
    switch(tts.setLanguage(loc)){

        case TextToSpeech.LANG_AVAILABLE:
            Log.i("TAG", "LANG_AVAILABLE");
            break;
        case TextToSpeech.LANG_COUNTRY_AVAILABLE:
            Log.i("TAG", "LANG_COUNTRY_AVAILABLE");
            break;
        case TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE:
            Log.i("TAG", "LANG_COUNTRY_VAR_AVAILABLE");
            break;
        case TextToSpeech.LANG_MISSING_DATA:
            Log.i("TAG", "LANG_MISSING_DATA");
            break;
        case TextToSpeech.LANG_NOT_SUPPORTED:
            Log.i("TAG", "LANG_NOT_SUPPORTED");
            break;
    }

字符串
请注意,对isLanguageAvailable()的回应是出了名的不可靠。至于原因,请参阅my edit on the answer here
最后,确保在onInit()返回SUCCESS之后设置TTS对象的语言

exdqitrt

exdqitrt2#

试试看:

t1.setLanguage( new Locale( "hin", "IND", "variant" ) );

字符串
我希望它会工作,如果它不是直到现在。

b4lqfgs4

b4lqfgs43#

在创建了一个TextToSpeech类的对象之后,你需要在TextToSpeech.OnInitListeneronInit()回调中配置它(或者检查它的可用状态/值)。你将在那里得到关于你的TextToSpeech对象的可靠信息。

private fun initTextToSpeech(){
    tts = TextToSpeech(this,this) // TextToSpeech(context,listener)
}

override fun onInit(status: Int) {
    Log.e(TAG, "onInit: status: $status")
    if(status!=TextToSpeech.SUCCESS)return

    val locale = Locale("hi","IN")

    val isLangCountryAvailable = tts.isLanguageAvailable(locale)
    Log.e(TAG, "onInit: isLangCountryAvailable: $isLangCountryAvailable")

    if(isLangCountryAvailable==TextToSpeech.LANG_COUNTRY_AVAILABLE) {
        val setLanguageResult = tts.setLanguage(locale)
        Log.e(TAG, "onInit: setLanguageResult: $setLanguageResult")
    }

    Log.e(TAG, "onInit: availableLanguages: ${tts.availableLanguages}")
    Log.e(TAG, "onInit: voice: ${tts.voice}")

    binding.btnSpeak.isEnabled = status==TextToSpeech.SUCCESS
}

字符串
我得到了以上onInit回调:

MainActivity: onInit: status: 0
MainActivity: onInit: isLangCountryAvailable: 1
MainActivity: onInit: setLanguageResult: 1
MainActivity: onInit: availableLanguages: [ko_KR, mr_IN, ru_RU, zh_TW, hu_HU, 
th_TH, ur_PK, nb_NO, da_DK, tr_TR, et_EE, bs, sw, pt_PT, vi_VN, en_US, sv_SE, 
ar, su_ID, bn_BD, gu_IN, kn_IN, el_GR, hi_IN, fi_FI, km_KH, bn_IN, fr_FR, 
uk_UA, en_AU, nl_NL, fr_CA, sr, pt_BR, ml_IN, si_LK, de_DE, ku, cs_CZ, pl_PL, 
sk_SK, fil_PH, it_IT, ne_NP, hr, en_NG, zh_CN, es_ES, cy, ta_IN, ja_JP, sq, 
yue_HK, en_IN, es_US, jv_ID, la, in_ID, te_IN, ro_RO, ca, en_GB]
MainActivity: onInit: voice: Voice[Name: hi-IN-language, locale: hi_IN, 
quality: 400, latency: 200, requiresNetwork: false, features: 
[networkTimeoutMs, legacySetLanguageVoice, networkRetriesCount]]

brqmpdu1

brqmpdu14#

试试这个。
t1.setLanguage(new Locale(“hi”,“IN”));
而不是
t1.setLanguage(new Locale(“hi_IN”));
我希望它会工作。

相关问题