本文介绍了以编程方式在android中将印地语设置为TextToSpeech语言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无法将印地语设置为 texttospeech 的语音语言,即使我的移动 tts 引擎完全支持印地语 textospeech

Unable to set hindi as speech language of texttospeech even though My mobile tts engine fully supports hindi textospeech

        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();

推荐答案

创建TextToSpeech 类的对象后,需要将其配置(或检查其可用状态/值)到TextToSpeech.OnInitListeneronInit() 回调.您将在那里获得有关 TextToSpeech 对象的可靠信息.

After creating an object of TextToSpeech class, you need to configure it (or check it's available state/values) into TextToSpeech.OnInitListener's onInit() callback. You will get reliable information there about your TextToSpeech object.

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 回调:

Logs I got for above onInit callback:

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]]

这篇关于以编程方式在android中将印地语设置为TextToSpeech语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-02 14:38