diff options
author | Jaromir Wysoglad | 2019-07-22 19:35:56 +0200 |
---|---|---|
committer | Filippos Karapetis | 2019-09-01 22:47:55 +0300 |
commit | 134d955006072720031c989a151ee14875bfcf05 (patch) | |
tree | 32357c42797ebf3cb115100a5cdfd89090455dcd /backends/text-to-speech | |
parent | 3027acc12e97fe92f617dd4a95a5861625773c38 (diff) | |
download | scummvm-rg350-134d955006072720031c989a151ee14875bfcf05.tar.gz scummvm-rg350-134d955006072720031c989a151ee14875bfcf05.tar.bz2 scummvm-rg350-134d955006072720031c989a151ee14875bfcf05.zip |
TTS: Add iconv implementation of strToUtf8
This might be useful in the future, because SDL cannot convert
from some important encodings (for example CP850)
Diffstat (limited to 'backends/text-to-speech')
-rw-r--r-- | backends/text-to-speech/linux/linux-text-to-speech.cpp | 36 |
1 files changed, 35 insertions, 1 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 d6195229c5..3914b0f347 100644 --- a/backends/text-to-speech/linux/linux-text-to-speech.cpp +++ b/backends/text-to-speech/linux/linux-text-to-speech.cpp @@ -28,6 +28,7 @@ #if defined(USE_LINUX_TTS) #include <speech-dispatcher/libspeechd.h> #include "backends/platform/sdl/sdl-sys.h" +//#include <iconv.h> #include "common/translation.h" #include "common/debug.h" @@ -116,9 +117,40 @@ Common::String LinuxTextToSpeechManager::strToUtf8(Common::String str, Common::S if (conv_text) { result = conv_text; SDL_free(conv_text); - } + } else if (charset != "ASCII"){ + warning("Could not convert text from %s to UTF-8, trying ASCII", charset.c_str()); + return strToUtf8(str, "ASCII"); + } else + warning("Could not convert text to UTF-8"); return result; + + // ICONV implementation (supports more charsets) + /*size_t inbytes = str.size(); + char *inStr = new char[inbytes + 1]; + char *in = inStr; + strcpy(inStr, str.c_str()); + + size_t outbytes = str.size() * 2 - 1; + char *destStr = new char[outbytes + 1]; + char *out = destStr; + iconv_t conv = iconv_open("UTF-8//IGNORE", charset.c_str()); + + if (conv == (iconv_t)-1) { + warning("Could not convert string from: %s to UTF-8", charset.c_str()); + return ""; + } + + if (iconv(conv, &in, &inbytes, &out, &outbytes) == (size_t)-1) { + warning("Could not convert string from: %s to UTF-8", charset.c_str()); + return ""; + } + + destStr[outbytes + 1] = 0; + Common::String result = destStr; + delete[] inStr; + delete[] destStr; + return result; */ #else return Common::String(); #endif @@ -135,6 +167,8 @@ bool LinuxTextToSpeechManager::say(Common::String str, Common::String charset) { charset = "ASCII"; #endif } + debug("charset: %s", charset.c_str()); + str = strToUtf8(str, charset); if (isSpeaking()) |