aboutsummaryrefslogtreecommitdiff
path: root/backends/text-to-speech
diff options
context:
space:
mode:
authorJaromir Wysoglad2019-07-18 13:34:22 +0200
committerFilippos Karapetis2019-09-01 22:47:55 +0300
commit5c1f562452e201a968063e176b55fc14d912aea1 (patch)
tree67d7d4bbabe1bc18f5aea429bb27cd511e1088cb /backends/text-to-speech
parent4d9572073192a3cefe7b148a27197c2ca9f60087 (diff)
downloadscummvm-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')
-rw-r--r--backends/text-to-speech/linux/linux-text-to-speech.cpp31
-rw-r--r--backends/text-to-speech/linux/linux-text-to-speech.h3
-rw-r--r--backends/text-to-speech/windows/windows-text-to-speech.cpp10
-rw-r--r--backends/text-to-speech/windows/windows-text-to-speech.h2
4 files changed, 39 insertions, 7 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
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 e9f28d966b..32087f5ccb 100644
--- a/backends/text-to-speech/windows/windows-text-to-speech.cpp
+++ b/backends/text-to-speech/windows/windows-text-to-speech.cpp
@@ -91,11 +91,19 @@ WindowsTextToSpeechManager::~WindowsTextToSpeechManager() {
::CoUninitialize();
}
-bool WindowsTextToSpeechManager::say(Common::String str) {
+bool WindowsTextToSpeechManager::say(Common::String str, Common::String charset) {
if(_speechState == BROKEN || _speechState == NO_VOICE) {
warning("The tts cannot speak in this state");
return true;
}
+
+ if (charset == "") {
+#ifdef USE_TRANSLATION
+ charset = TransMan.getCurrentCharset();
+#else
+ charset = "ASCII";
+#endif
+ }
if (isPaused()) {
resume();
}
diff --git a/backends/text-to-speech/windows/windows-text-to-speech.h b/backends/text-to-speech/windows/windows-text-to-speech.h
index 2ae062ce92..848ae854eb 100644
--- a/backends/text-to-speech/windows/windows-text-to-speech.h
+++ b/backends/text-to-speech/windows/windows-text-to-speech.h
@@ -43,7 +43,7 @@ public:
WindowsTextToSpeechManager();
virtual ~WindowsTextToSpeechManager();
- virtual bool say(Common::String str);
+ virtual bool say(Common::String str, Common::String charset = "");
virtual bool stop();
virtual bool pause();