diff options
author | Jaromir Wysoglad | 2019-07-18 13:34:22 +0200 |
---|---|---|
committer | Filippos Karapetis | 2019-09-01 22:47:55 +0300 |
commit | 5c1f562452e201a968063e176b55fc14d912aea1 (patch) | |
tree | 67d7d4bbabe1bc18f5aea429bb27cd511e1088cb /backends/text-to-speech/linux | |
parent | 4d9572073192a3cefe7b148a27197c2ca9f60087 (diff) | |
download | scummvm-rg350-5c1f562452e201a968063e176b55fc14d912aea1.tar.gz scummvm-rg350-5c1f562452e201a968063e176b55fc14d912aea1.tar.bz2 scummvm-rg350-5c1f562452e201a968063e176b55fc14d912aea1.zip |
TTS: Implement conversion to UTF-8 in say on linux
Diffstat (limited to 'backends/text-to-speech/linux')
-rw-r--r-- | backends/text-to-speech/linux/linux-text-to-speech.cpp | 31 | ||||
-rw-r--r-- | backends/text-to-speech/linux/linux-text-to-speech.h | 3 |
2 files changed, 29 insertions, 5 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 db036e053a..4241b76c7b 100644 --- a/backends/text-to-speech/linux/linux-text-to-speech.cpp +++ b/backends/text-to-speech/linux/linux-text-to-speech.cpp @@ -27,6 +27,7 @@ #if defined(USE_LINUX_TTS) #include <speech-dispatcher/libspeechd.h> +#include "backends/platform/sdl/sdl-sys.h" #include "common/translation.h" #include "common/debug.h" @@ -107,13 +108,35 @@ void LinuxTextToSpeechManager::updateState(LinuxTextToSpeechManager::SpeechState _speechState = state; } -bool LinuxTextToSpeechManager::say(Common::String str) { +Common::String LinuxTextToSpeechManager::strToUtf8(Common::String str, Common::String charset) { +#if SDL_VERSION_ATLEAST(2, 0, 0) + + char *conv_text = SDL_iconv_string("UTF-8", charset.c_str(), str.c_str(), str.size() + 1); + Common::String result; + if (conv_text) { + result = conv_text; + SDL_free(conv_text); + } + + return result; +#else + return Common::String(); +#endif +} + +bool LinuxTextToSpeechManager::say(Common::String str, Common::String charset) { if (_speechState == BROKEN) return true; - //Convert string, that might have foreign characters to UTF-8 - if (ConfMan.get("gui_language") != "C") { - str = Common::convertUtf32ToUtf8(Common::convertToU32String(str.c_str(), Common::kWindows1250)).c_str(); + + if (charset == "") { +#ifdef USE_TRANSLATION + charset = TransMan.getCurrentCharset(); +#else + charset = "ASCII"; +#endif } + str = strToUtf8(str, charset); + if (isSpeaking()) stop(); debug("say: %s", str.c_str()); diff --git a/backends/text-to-speech/linux/linux-text-to-speech.h b/backends/text-to-speech/linux/linux-text-to-speech.h index 57b9aeea60..1bb3ad5ce2 100644 --- a/backends/text-to-speech/linux/linux-text-to-speech.h +++ b/backends/text-to-speech/linux/linux-text-to-speech.h @@ -42,7 +42,7 @@ public: LinuxTextToSpeechManager(); virtual ~LinuxTextToSpeechManager(); - virtual bool say(Common::String str); + virtual bool say(Common::String str, Common::String charset = ""); virtual bool stop(); virtual bool pause(); @@ -74,6 +74,7 @@ private: virtual void updateVoices(); void createVoice(int typeNumber, Common::TTSVoice::Gender, Common::TTSVoice::Age, char *description); SpeechState _speechState; + Common::String strToUtf8(Common::String str, Common::String charset); }; #endif |