aboutsummaryrefslogtreecommitdiff
path: root/backends/text-to-speech
diff options
context:
space:
mode:
authorJaromir Wysoglad2019-08-26 16:48:22 +0200
committerFilippos Karapetis2019-09-01 22:47:55 +0300
commit55c399c7c0ebe4084c1bdf31e647cfa50cc01c09 (patch)
treeda06bf1c4ad5f18ed4220df1682c3ea00626788b /backends/text-to-speech
parent6baa9c8ddb524f3d0ca91f34f2d3ddc2c055a6cd (diff)
downloadscummvm-rg350-55c399c7c0ebe4084c1bdf31e647cfa50cc01c09.tar.gz
scummvm-rg350-55c399c7c0ebe4084c1bdf31e647cfa50cc01c09.tar.bz2
scummvm-rg350-55c399c7c0ebe4084c1bdf31e647cfa50cc01c09.zip
TTS: Use Common::Encoding for encoding conversion.
Diffstat (limited to 'backends/text-to-speech')
-rw-r--r--backends/text-to-speech/linux/linux-text-to-speech.cpp41
-rw-r--r--backends/text-to-speech/windows/windows-text-to-speech.cpp8
2 files changed, 20 insertions, 29 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 d2010831b3..ccedb6bf6b 100644
--- a/backends/text-to-speech/linux/linux-text-to-speech.cpp
+++ b/backends/text-to-speech/linux/linux-text-to-speech.cpp
@@ -27,12 +27,12 @@
#if defined(USE_TTS) && defined(USE_SPEECH_DISPATCHER) && defined(POSIX)
#include <speech-dispatcher/libspeechd.h>
-#include "backends/platform/sdl/sdl-sys.h"
#include "common/translation.h"
#include "common/system.h"
#include "common/ustr.h"
#include "common/config-manager.h"
+#include "common/encoding.h"
#include <pthread.h>
SPDConnection *_connection;
@@ -175,26 +175,6 @@ void SpeechDispatcherManager::updateState(SpeechDispatcherManager::SpeechEvent e
}
}
-Common::String SpeechDispatcherManager::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);
- } 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;
-#else
- return Common::String();
-#endif
-}
-
bool SpeechDispatcherManager::say(Common::String str, Action action, Common::String charset) {
pthread_mutex_lock(&_speechMutex);
@@ -220,18 +200,25 @@ bool SpeechDispatcherManager::say(Common::String str, Action action, Common::Str
#endif
}
- str = strToUtf8(str, charset);
+ char *tmpStr = Common::Encoding::convert("UTF-8", charset, str.c_str(), str.size());
+ if (tmpStr == nullptr) {
+ warning("Cannot convert from %s encoding for text to speech", charset.c_str());
+ pthread_mutex_unlock(&_speechMutex);
+ return true;
+ }
+ Common::String strUtf8 = tmpStr;
+ free(tmpStr);
if (!_speechQueue.empty() && action == INTERRUPT_NO_REPEAT &&
- _speechQueue.front() == str && isSpeaking()) {
+ _speechQueue.front() == strUtf8 && isSpeaking()) {
_speechQueue.clear();
- _speechQueue.push_back(str);
+ _speechQueue.push_back(strUtf8);
pthread_mutex_unlock(&_speechMutex);
return true;
}
if (!_speechQueue.empty() && action == QUEUE_NO_REPEAT &&
- _speechQueue.back() == str && isSpeaking()) {
+ _speechQueue.back() == strUtf8 && isSpeaking()) {
pthread_mutex_unlock(&_speechMutex);
return true;
}
@@ -239,9 +226,9 @@ bool SpeechDispatcherManager::say(Common::String str, Action action, Common::Str
pthread_mutex_unlock(&_speechMutex);
if (isSpeaking() && (action == INTERRUPT || action == INTERRUPT_NO_REPEAT))
stop();
- if (!str.empty()) {
+ if (!strUtf8.empty()) {
pthread_mutex_lock(&_speechMutex);
- _speechQueue.push_back(str);
+ _speechQueue.push_back(strUtf8);
pthread_mutex_unlock(&_speechMutex);
if (isReady()) {
_speechState = SPEAKING;
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 b7d39f0286..a59f21952b 100644
--- a/backends/text-to-speech/windows/windows-text-to-speech.cpp
+++ b/backends/text-to-speech/windows/windows-text-to-speech.cpp
@@ -32,7 +32,6 @@
#include <sapi.h>
#include "backends/text-to-speech/windows/sphelper-scummvm.h"
#include "backends/platform/sdl/win32/win32_wrapper.h"
-#include "backends/platform/sdl/win32/codepage.h"
#include "backends/text-to-speech/windows/windows-text-to-speech.h"
@@ -41,6 +40,7 @@
#include "common/system.h"
#include "common/ustr.h"
#include "common/config-manager.h"
+#include "common/encoding.h"
ISpVoice *_voice;
@@ -174,7 +174,11 @@ bool WindowsTextToSpeechManager::say(Common::String str, Action action, Common::
// We have to set the pitch by prepending xml code at the start of the said string;
Common::String pitch= Common::String::format("<pitch absmiddle=\"%d\">", _ttsState->_pitch / 10);
str.replace((uint32)0, 0, pitch);
- WCHAR *strW = Win32::ansiToUnicode(str.c_str(), Win32::getCodePageId(charset));
+ WCHAR *strW = (WCHAR *) Common::Encoding::convert("UTF-16", charset, str.c_str(), str.size());
+ if (strW == nullptr) {
+ warning("Cannot convert from %s encoding for text to speech", charset.c_str());
+ return true;
+ }
WaitForSingleObject(_speechMutex, INFINITE);
if (isSpeaking() && !_speechQueue.empty() && action == INTERRUPT_NO_REPEAT &&