diff options
author | Jaromir Wysoglad | 2019-10-16 18:42:16 +0200 |
---|---|---|
committer | Jaromir Wysoglad | 2019-10-16 19:30:56 +0200 |
commit | b9d3c84db4e10cc0e55e4c2a12e288c17c7e66d2 (patch) | |
tree | a2c4d3931b78579b04a737094d29e2b6cf21a278 | |
parent | 94d17b1853a77db0bf34cb6192d88a58d0766130 (diff) | |
download | scummvm-rg350-b9d3c84db4e10cc0e55e4c2a12e288c17c7e66d2.tar.gz scummvm-rg350-b9d3c84db4e10cc0e55e4c2a12e288c17c7e66d2.tar.bz2 scummvm-rg350-b9d3c84db4e10cc0e55e4c2a12e288c17c7e66d2.zip |
TTS: Fix language setting.
-rw-r--r-- | backends/text-to-speech/linux/linux-text-to-speech.cpp | 4 | ||||
-rw-r--r-- | backends/text-to-speech/windows/windows-text-to-speech.cpp | 6 | ||||
-rw-r--r-- | common/text-to-speech.cpp | 13 | ||||
-rw-r--r-- | common/text-to-speech.h | 2 | ||||
-rw-r--r-- | gui/gui-manager.cpp | 2 | ||||
-rw-r--r-- | gui/options.cpp | 3 |
6 files changed, 19 insertions, 11 deletions
diff --git a/backends/text-to-speech/linux/linux-text-to-speech.cpp b/backends/text-to-speech/linux/linux-text-to-speech.cpp index ccedb6bf6b..5943b69f49 100644 --- a/backends/text-to-speech/linux/linux-text-to-speech.cpp +++ b/backends/text-to-speech/linux/linux-text-to-speech.cpp @@ -330,8 +330,8 @@ void SpeechDispatcherManager::setVolume(unsigned volume) { void SpeechDispatcherManager::setLanguage(Common::String language) { if (_speechState == BROKEN) return; - spd_set_language(_connection, language.c_str()); - _ttsState->_language = language; + Common::TextToSpeechManager::setLanguage(language); + spd_set_language(_connection, _ttsState->_language.c_str()); setVoice(_ttsState->_activeVoice); } diff --git a/backends/text-to-speech/windows/windows-text-to-speech.cpp b/backends/text-to-speech/windows/windows-text-to-speech.cpp index 0e794d7baa..2b405f5553 100644 --- a/backends/text-to-speech/windows/windows-text-to-speech.cpp +++ b/backends/text-to-speech/windows/windows-text-to-speech.cpp @@ -338,9 +338,7 @@ void WindowsTextToSpeechManager::setVolume(unsigned volume) { } void WindowsTextToSpeechManager::setLanguage(Common::String language) { - if (language == "C") - language = "en"; - _ttsState->_language = language; + Common::TextToSpeechManager::setLanguage(language); updateVoices(); setVoice(0); } @@ -471,7 +469,7 @@ void WindowsTextToSpeechManager::updateVoices() { if (_ttsState->_availableVoices.empty()) { _speechState = NO_VOICE; - warning("No voice is available"); + warning("No voice is available for language: %s", _ttsState->_language.c_str()); } else if (_speechState == NO_VOICE) _speechState = READY; } diff --git a/common/text-to-speech.cpp b/common/text-to-speech.cpp index cdfc8ab77f..fa74e53c36 100644 --- a/common/text-to-speech.cpp +++ b/common/text-to-speech.cpp @@ -145,5 +145,18 @@ Array<int> TextToSpeechManager::getVoiceIndicesByGender(TTSVoice::Gender gender) return results; } +void TextToSpeechManager::setLanguage(Common::String language) { + if (language == "C") + language = "en"; + // The speech manager uses the ISO 639-1 for language codes (2 letter code) + // if we get a longer language string, just take the first 2 letters from that + // if it won't be a valid language code, the Manager just won't find any voice + // for it. This way a code like (en_GB) can also be passed to this. + if (language.size() > 2) { + language.erase(2, Common::String::npos); + } + _ttsState->_language = language; +} + } #endif diff --git a/common/text-to-speech.h b/common/text-to-speech.h index 8e86721701..14cbab17a5 100644 --- a/common/text-to-speech.h +++ b/common/text-to-speech.h @@ -271,7 +271,7 @@ public: * because voices are usually language specific and so it is set to some platform * specific default after switching languages. */ - virtual void setLanguage(String language) { _ttsState->_language = language; } + virtual void setLanguage(String language); /** * Returns the current speech language diff --git a/gui/gui-manager.cpp b/gui/gui-manager.cpp index 5a39746bad..659d87bef2 100644 --- a/gui/gui-manager.cpp +++ b/gui/gui-manager.cpp @@ -638,8 +638,6 @@ void GuiManager::initTextToSpeech() { Common::String currentLanguage = TransMan.getCurrentLanguage(); if (currentLanguage == "C") currentLanguage = "en"; - else - currentLanguage.setChar('\0', 2); ttsMan->setLanguage(currentLanguage); #endif int volume = (ConfMan.getInt("speech_volume", "scummvm") * 100) / 256; diff --git a/gui/options.cpp b/gui/options.cpp index 073d04b0a9..6cf7df0f08 100644 --- a/gui/options.cpp +++ b/gui/options.cpp @@ -2158,8 +2158,7 @@ void GlobalOptionsDialog::apply() { if (newLang == "C") ttsMan->setLanguage("en"); else { - Common::String guiLang(newLang.c_str(), 2); - ttsMan->setLanguage(guiLang); + ttsMan->setLanguage(newLang); } _ttsVoiceSelectionPopUp->setSelectedTag(0); } |