Android TTS检查支持的语言环境是否丢失/未下载语音数据 [英] Android TTS checking for supported locale with missing/not downloaded voice data

查看:124
本文介绍了Android TTS检查支持的语言环境是否丢失/未下载语音数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Android的TextToSpeech类.一切正常.但是,有些语言/语言区域默认情况下未安装,但TTS引擎支持这些语言/语言,因此我无法捕获丢失的语音数据的状态.

在Internet上,当我尝试将Language设置为尚未下载其语音数据的新语言环境时,它将简单地下载语音数据并正常/成功执行语音方法.

但是,在关闭Internet的情况下,当我尝试将Language设置为尚未下载其语音数据的新语言环境时,它将尝试下载语音数据.但是没有互联网,它只是在所选语言环境的语言和输入"下的"TTS语音数据"设置屏幕上指示正在下载",没有任何进展.正如预期的那样,由于未下载语音数据,所以语音方法不起作用.发生这种情况时,我认为TTS方法setLanguage/isLanguageAvailable将为我返回LANG_MISSING_DATA来捕获此状态,但是,它只是返回LANG_COUNTRY_AVAILABLE.这种情况显示在此图像中:

我希望能够检测到所选语言环境的语音数据何时没有下载/丢失,并发出祝酒消息或直接用户下载.我看过几篇建议使用isLanguageAvailable这样的帖子

解决方案

您可以使用以下功能找到设备的所有可用语言环境.希望这段代码对您有所帮助.

 区域设置loc = new Locale("en");Locale [] availableLocales = loc.getAvailableLocales();布尔值available = Boolean.FALSE;为(int i = 0; i< availableLocales.length; i ++){if(availableLocales [i] .getDisplayLanguage().equals("your_locale_language"))){available = Boolean.TRUE;//去做:}} 

I'm using Android's TextToSpeech class. Everything is working normally. However, there are languages/locales that aren't installed by default but supported by the TTS engine and I can't capture the state of missing voice data.

With the internet on, when I try to setLanguage to a new locale which its voice data hasn't been downloaded, it'll simply download the voice data and perform the speak method normally/successfully.

However, with internet off, when I try to setLanguage to a new locale which its voice data hasn't been downloaded, it attempts to download the voice data. But with no internet, it just indicates "downloading" on the "TTS voice data" settings screen under "Language and input" for the selected locale, without any progress. And as expected the speak method doesn't work since the voice data isn't downloaded. When this happens, I would think TTS methods setLanguage/isLanguageAvailable will return LANG_MISSING_DATA for me to capture this state, however, it simply returns LANG_COUNTRY_AVAILABLE. The situation is shown in this image:

I want to be able to detect when the voice data of the locale being chosen isn't downloaded/missing and either give a toast message or direct user to download it. I have seen several posts suggesting the use of using isLanguageAvailable like this one. I also looked at the android documentation and it seems like isLanguageAvailable's return values should capture the state of missing voice data with LANG_MISSING_DATA.

I also tried sending an intent with ACTION_CHECK_TTS_DATA as the other way to check for missing data as suggested in the Android documentation I linked. However, the resultCode again didn't capture/indicate that the voice data is missing (CHECK_VOICE_DATA_FAIL) but returned CHECK_VOICE_DATA_PASS instead.

In this case, how should I capture the state of a language/locale being available/supported, with the voice data missing? I'm also curious why CHECK_VOICE_DATA_PASS and LANG_MISSING_DATA aren't the values returned. When the voice data is missing, shouldn't it return these values? Thanks! Below is the return value when I try to use setLanguage and isLanguageAvailable on locales that haven't had its voice data downloaded (0 and 1 are the returned value of the method shown in the logs, -1 is the one that corresponds to missing voice data):

解决方案

You can find all available Locale of the device using following function. hope this code will help you.

 Locale loc = new Locale("en");
 Locale[] availableLocales= loc.getAvailableLocales();
 Boolean available=Boolean.FALSE;
 for (int i=0;i<availableLocales.length;i++)
 {
  if(availableLocales[i].getDisplayLanguage().equals("your_locale_language"))
   {
        available=Boolean.TRUE;
        // TODO:  
   }
 }

这篇关于Android TTS检查支持的语言环境是否丢失/未下载语音数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆