State that TTS language is not supported if not in available list.

Bad TTS implementation of isLanguageAvailable may cause settings to
think that given language is available. This change adds additional
check, by searching locale in list of available locales returned
form TTS CheckVoiceData activity.

Bug: 9982002
Change-Id: Ic91cd1218349b8241e3f40f2343df52f3d900544
This commit is contained in:
Przemyslaw Szczepaniak
2013-08-06 13:55:52 +01:00
parent 5459b722ca
commit 6ada2d5547
2 changed files with 49 additions and 6 deletions

View File

@@ -3569,12 +3569,14 @@
selected language is fully supported by the engine [CHAR LIMIT=150]--> selected language is fully supported by the engine [CHAR LIMIT=150]-->
<string name="tts_status_ok"><xliff:g id="locale" example="English (United States)">%1$s</xliff:g> is fully supported</string> <string name="tts_status_ok"><xliff:g id="locale" example="English (United States)">%1$s</xliff:g> is fully supported</string>
<!-- On main TTS Settings screen, current TTS engine status for the current default language, <!-- On main TTS Settings screen, current TTS engine status for the current default language,
selected language is supported by the engine only if there's a working network connection selected language is supported by the engine only if there's a working network connection [CHAR LIMIT=150] -->
[CHAR LIMIT=150]-->
<string name="tts_status_requires_network"><xliff:g id="locale" example="English (United States)">%1$s</xliff:g> requires network connection</string> <string name="tts_status_requires_network"><xliff:g id="locale" example="English (United States)">%1$s</xliff:g> requires network connection</string>
<!-- On main TTS Settings screen, current TTS engine status for the current default language, <!-- On main TTS Settings screen, current TTS engine status for the current default language,
selected language is not supported by the engine [CHAR LIMIT=150] --> selected language is not supported by the engine [CHAR LIMIT=150] -->
<string name="tts_status_not_supported"><xliff:g id="locale" example="English (United States)">%1$s</xliff:g> is not supported</string> <string name="tts_status_not_supported"><xliff:g id="locale" example="English (United States)">%1$s</xliff:g> is not supported</string>
<!-- On main TTS Settings screen, current TTS engine status for the current default language,
tts engine is queried for status [CHAR LIMIT=150] -->
<string name="tts_status_checking">Checking...</string>
<!-- On main TTS Settings screen, text for divider under which all TTS engines are listed --> <!-- On main TTS Settings screen, text for divider under which all TTS engines are listed -->
<string name="tts_engines_section">Engines</string> <string name="tts_engines_section">Engines</string>
<!-- On main TTS Settings screen, text preceded by the TTS engine name, clicking this button will launch the engine settings --> <!-- On main TTS Settings screen, text preceded by the TTS engine name, clicking this button will launch the engine settings -->

View File

@@ -42,6 +42,7 @@ import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import android.widget.Checkable; import android.widget.Checkable;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
@@ -104,6 +105,7 @@ public class TextToSpeechSettings extends SettingsPreferenceFragment implements
private String mSampleText = ""; private String mSampleText = "";
private Locale mCurrentDefaultLocale; private Locale mCurrentDefaultLocale;
private List<String> mAvailableStrLocals;
/** /**
* The initialization listener used when we are initalizing the settings * The initialization listener used when we are initalizing the settings
@@ -144,6 +146,7 @@ public class TextToSpeechSettings extends SettingsPreferenceFragment implements
mDefaultRatePref = (ListPreference) findPreference(KEY_DEFAULT_RATE); mDefaultRatePref = (ListPreference) findPreference(KEY_DEFAULT_RATE);
mEngineStatus = findPreference(KEY_STATUS); mEngineStatus = findPreference(KEY_STATUS);
updateEngineStatus(R.string.tts_status_checking);
mTts = new TextToSpeech(getActivity().getApplicationContext(), mInitListener); mTts = new TextToSpeech(getActivity().getApplicationContext(), mInitListener);
mEnginesHelper = new TtsEngines(getActivity().getApplicationContext()); mEnginesHelper = new TtsEngines(getActivity().getApplicationContext());
@@ -253,17 +256,50 @@ public class TextToSpeechSettings extends SettingsPreferenceFragment implements
mCurrentDefaultLocale = defaultLocale; mCurrentDefaultLocale = defaultLocale;
int defaultAvailable = mTts.setLanguage(defaultLocale); int defaultAvailable = mTts.setLanguage(defaultLocale);
if (defaultAvailable == TextToSpeech.LANG_NOT_SUPPORTED) { if (evaluateDefaultLocale()) {
getSampleText();
}
}
private boolean evaluateDefaultLocale() {
if (mCurrentDefaultLocale == null) {
return false;
}
int defaultAvailable = mTts.setLanguage(mCurrentDefaultLocale);
// Check if language is listed in CheckVoices Action result as available voice.
String defaultLocaleStr = mCurrentDefaultLocale.getISO3Language();
boolean notInAvailableLangauges = true;
if (!TextUtils.isEmpty(mCurrentDefaultLocale.getISO3Country())) {
defaultLocaleStr += "-" + mCurrentDefaultLocale.getISO3Country();
}
if (!TextUtils.isEmpty(mCurrentDefaultLocale.getVariant())) {
defaultLocaleStr += "-" + mCurrentDefaultLocale.getVariant();
}
if (mAvailableStrLocals != null) {
for (String loc : mAvailableStrLocals) {
if (loc.equalsIgnoreCase(defaultLocaleStr)) {
notInAvailableLangauges = false;
break;
}
}
}
if (defaultAvailable == TextToSpeech.LANG_NOT_SUPPORTED ||
defaultAvailable == TextToSpeech.LANG_MISSING_DATA ||
mAvailableStrLocals != null && notInAvailableLangauges) {
if (DBG) Log.d(TAG, "Default locale for this TTS engine is not supported."); if (DBG) Log.d(TAG, "Default locale for this TTS engine is not supported.");
updateWidgetState(false);
updateEngineStatus(R.string.tts_status_not_supported); updateEngineStatus(R.string.tts_status_not_supported);
updateWidgetState(false);
return false;
} else { } else {
if (isNetworkRequiredForSynthesis()) { if (isNetworkRequiredForSynthesis()) {
updateEngineStatus(R.string.tts_status_requires_network); updateEngineStatus(R.string.tts_status_requires_network);
} else { } else {
updateEngineStatus(R.string.tts_status_ok); updateEngineStatus(R.string.tts_status_ok);
} }
getSampleText(); updateWidgetState(true);
return true;
} }
} }
@@ -431,6 +467,7 @@ public class TextToSpeechSettings extends SettingsPreferenceFragment implements
// Disable the "play sample text" preference and the speech // Disable the "play sample text" preference and the speech
// rate preference while the engine is being swapped. // rate preference while the engine is being swapped.
updateWidgetState(false); updateWidgetState(false);
updateEngineStatus(R.string.tts_status_checking);
// Keep track of the previous engine that was being used. So that // Keep track of the previous engine that was being used. So that
// we can reuse the previous engine. // we can reuse the previous engine.
@@ -515,6 +552,10 @@ public class TextToSpeechSettings extends SettingsPreferenceFragment implements
Settings.Secure.putString(getContentResolver(), TTS_DEFAULT_SYNTH, engine); Settings.Secure.putString(getContentResolver(), TTS_DEFAULT_SYNTH, engine);
mAvailableStrLocals = data.getStringArrayListExtra(
TextToSpeech.Engine.EXTRA_AVAILABLE_VOICES);
evaluateDefaultLocale();
final int engineCount = mEnginePreferenceCategory.getPreferenceCount(); final int engineCount = mEnginePreferenceCategory.getPreferenceCount();
for (int i = 0; i < engineCount; ++i) { for (int i = 0; i < engineCount; ++i) {
final Preference p = mEnginePreferenceCategory.getPreference(i); final Preference p = mEnginePreferenceCategory.getPreference(i);