Checking Android TTS for a supported language with missing / not loaded voice data

I am using Android TextToSpeech class. Everything is working fine. However, there are languages ​​/ locales that are not installed by default, but are supported by the TTS mechanism, and I cannot fix the state of the missing speech data.

When connected to the Internet, when I try to set the language to a new locale that its speech data has not been downloaded, it will just download the voice data and execute the conversation method normally / successfully.

However, when I turn off the Internet, when I try to install LanguageLanguage in a new locale that its voice data has not been downloaded, it tries to download voice data. But without the Internet, it simply indicates a “download” on the “TTS voice data” settings screen in the “Language and input” section for the selected language, without any success. And, as expected, the conversation method does not work because voice data is not loading. When this happens, I think the TTS setLanguage / isLanguageAvailable methods will return LANG_MISSING_DATA to me to capture this state, however it just returns LANG_COUNTRY_AVAILABLE. The situation is shown in this image: enter image description here

I want to be able to detect when the speech data of the selected locale is not loaded / missing, and also give a toast message or direct user to download it. I have seen several posts suggesting using isLanguageAvailable, like this one . I also looked at the Android documentation and it seems that the returned isLanguageAvailable values ​​should fix the state of the missing voice data using LANG_MISSING_DATA.

I also tried sending the intent with ACTION_CHECK_TTS_DATA, as another way to check for missing data, as suggested in the Android documentation that I linked. However, resultCode again did not commit / indicate that there is no voice data (CHECK_VOICE_DATA_FAIL), but CHECK_VOICE_DATA_PASS is returned instead.

In this case, how should I display the language / locale status, available / supported, in the absence of voice data? I am also wondering why CHECK_VOICE_DATA_PASS and LANG_MISSING_DATA are not return values. When no voice data is available, should these values ​​be returned? Thank you The following is the return value when I try to use setLanguage and isLanguageAvailable on locales that haven’t downloaded its voice data (0 and 1 is the return value of the method shown in the logs, -1 is the one that corresponds to the missing voice data): enter image description here

+12
android android-intent text-to-speech
source share
4 answers

You can find all available device locales using the following function. hope this code helps 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: } } 
+5
source share

I have this implementation as part of a wrapper class to work with TextToSpeech, I hope this helps:

 public boolean isLanguageAvailable(Locale language) { if(language == null) return false; boolean available = false; switch (tts.isLanguageAvailable(language)) { case TextToSpeech.LANG_AVAILABLE: case TextToSpeech.LANG_COUNTRY_AVAILABLE: case TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE: if(Build.VERSION.SDK_INT >= 21){ tts.setLanguage(language); Voice voice = tts.getVoice(); if(voice != null){ Set<String> features = voice.getFeatures(); if (features != null && !features.contains(TextToSpeech.Engine.KEY_FEATURE_NOT_INSTALLED)) available = true; } else available = false; tts.setLanguage(this.language); } break; case TextToSpeech.LANG_MISSING_DATA: case TextToSpeech.LANG_NOT_SUPPORTED: default: break; } return available; } 
+2
source share

This seems like a welcome question, but anyway. It seems that you need to check the voice functions to find out this:

 Set<String> features = voice.getFeatures(); if (features.contains(TextToSpeech.Engine.KEY_FEATURE_NOT_INSTALLED)) { //Voice data needs to be downloaded ... } 
+1
source share

No voice data in dictionaries

0
source share

All Articles