diff options
author | Jean-Michel Trivi <jmtrivi@google.com> | 2011-01-04 18:59:53 -0800 |
---|---|---|
committer | Jean-Michel Trivi <jmtrivi@google.com> | 2011-01-04 19:18:33 -0800 |
commit | 410a1a0acbd50d7a73f0b2dbfc3e52c0808fc98d (patch) | |
tree | 6b970dcc9a95efd7ad2a0fb66851a61093dc3773 | |
parent | 02fa8dfc571a1f292b72e350f99be2185082b579 (diff) | |
download | external_svox-410a1a0acbd50d7a73f0b2dbfc3e52c0808fc98d.zip external_svox-410a1a0acbd50d7a73f0b2dbfc3e52c0808fc98d.tar.gz external_svox-410a1a0acbd50d7a73f0b2dbfc3e52c0808fc98d.tar.bz2 |
Fix bug 2782425 Use the current language if it matches that of the document
If an utterance specifies its locale, the checkForLocale() function
looks for the index of the supported language that matches it. If
the exact locale is not supported, we look for language-only support.
But there could already be a match with the currently loaded language.
The fix consists in comparing the requested language with the one
that is loaded (if any), so we don't load a new one uselessly, AND
so the default language is used if it matches.
Change-Id: I501d946459ea982466eb804b17e9c43a8203564a
-rw-r--r-- | pico/tts/com_svox_picottsengine.cpp | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/pico/tts/com_svox_picottsengine.cpp b/pico/tts/com_svox_picottsengine.cpp index b945fd5..d614cb4 100644 --- a/pico/tts/com_svox_picottsengine.cpp +++ b/pico/tts/com_svox_picottsengine.cpp @@ -142,18 +142,28 @@ static int checkForLocale( const char * locale ) } }; - /* The locale was not found. */ + /* The exact locale was not found. */ if (found < 0) { /* We didn't find an exact match; it may have been specified with only the first 2 characters. This could overmatch ISO 639-3 language codes.%% */ - for (i = 0; i < picoNumSupportedVocs; i ++) { - if (strncmp(locale, picoSupportedLang[i], 2) == 0) { - found = i; - break; + + /* check whether the current language matches the locale's language */ + if ((picoCurrentLangIndex > -1) && + (strncmp(locale, picoSupportedLang[picoCurrentLangIndex], 2) == 0)) { + /* the current language matches the requested language, let's use it */ + found = picoCurrentLangIndex; + } else { + /* check whether we can find a match at least on the language */ + for (i = 0; i < picoNumSupportedVocs; i ++) { + if (strncmp(locale, picoSupportedLang[i], 2) == 0) { + found = i; + break; + } } } + if (found < 0) { - LOGE("TtsEngine::set language called with unsupported locale"); + LOGE("TtsEngine::set language called with unsupported locale %s", locale); } }; return found; @@ -301,8 +311,8 @@ static tts_result doLanguageSwitchFromLangIndex( int langIndex ) if (langIndex>=0) { /* If we already have a loaded locale, check whether it is the same one as requested. */ if (picoProp_currLang && (strcmp(picoProp_currLang, picoSupportedLang[langIndex]) == 0)) { - LOGI("Language already loaded (%s == %s)", picoProp_currLang, - picoSupportedLang[langIndex]); + //LOGI("Language already loaded (%s == %s)", picoProp_currLang, + // picoSupportedLang[langIndex]); return TTS_SUCCESS; } } @@ -500,7 +510,7 @@ static tts_result doLanguageSwitch( const char * locale ) LOGE("Tried to swith to non-supported locale %s", locale); return TTS_FAILURE; } - LOGI("Found supported locale %s", picoSupportedLang[loclIndex]); + //LOGI("Found supported locale %s", picoSupportedLang[loclIndex]); return doLanguageSwitchFromLangIndex( loclIndex ); } @@ -1115,6 +1125,7 @@ tts_result TtsEngine::loadLanguage(const char *lang, const char *country, const */ tts_result TtsEngine::setLanguage( const char * lang, const char * country, const char * variant ) { + //LOGI("TtsEngine::setLanguage %s %s %s", lang, country, variant); int langIndex; int countryIndex; int i; |