aboutsummaryrefslogtreecommitdiff
path: root/backends/text-to-speech
diff options
context:
space:
mode:
authorJaromir Wysoglad2019-07-31 15:10:12 +0200
committerFilippos Karapetis2019-09-01 22:47:55 +0300
commit6703f88f7f91bc22ce5ea3593a1699f1dc4fa7c0 (patch)
treeb277c6509b1bd632669b5de0fd1d0f66a567b880 /backends/text-to-speech
parentbbbb608c528699f281fdd5a8a7d814dd44b9aa41 (diff)
downloadscummvm-rg350-6703f88f7f91bc22ce5ea3593a1699f1dc4fa7c0.tar.gz
scummvm-rg350-6703f88f7f91bc22ce5ea3593a1699f1dc4fa7c0.tar.bz2
scummvm-rg350-6703f88f7f91bc22ce5ea3593a1699f1dc4fa7c0.zip
TTS: Implement speech queueing on Linux and Win
Diffstat (limited to 'backends/text-to-speech')
-rw-r--r--backends/text-to-speech/linux/linux-text-to-speech.cpp7
-rw-r--r--backends/text-to-speech/linux/linux-text-to-speech.h2
-rw-r--r--backends/text-to-speech/windows/windows-text-to-speech.cpp22
-rw-r--r--backends/text-to-speech/windows/windows-text-to-speech.h2
4 files changed, 19 insertions, 14 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 828eb877b3..a2a09aebdc 100644
--- a/backends/text-to-speech/linux/linux-text-to-speech.cpp
+++ b/backends/text-to-speech/linux/linux-text-to-speech.cpp
@@ -128,9 +128,12 @@ Common::String LinuxTextToSpeechManager::strToUtf8(Common::String str, Common::S
#endif
}
-bool LinuxTextToSpeechManager::say(Common::String str, Common::String charset) {
+bool LinuxTextToSpeechManager::say(Common::String str, Action action, Common::String charset) {
if (_speechState == BROKEN)
return true;
+
+ if (action == DROP && isSpeaking())
+ return true;
if (charset.empty()) {
#ifdef USE_TRANSLATION
@@ -142,7 +145,7 @@ bool LinuxTextToSpeechManager::say(Common::String str, Common::String charset) {
str = strToUtf8(str, charset);
- if (isSpeaking())
+ if (isSpeaking() && action == INTERRUPT)
stop();
if(spd_say(_connection, SPD_MESSAGE, str.c_str()) == -1) {
//restart the connection
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 fe7eab8ed5..49701abb4c 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, Common::String charset = "");
+ virtual bool say(Common::String str, Action action, Common::String charset = "");
virtual bool stop();
virtual bool pause();
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 21ab0242b1..196a909f2e 100644
--- a/backends/text-to-speech/windows/windows-text-to-speech.cpp
+++ b/backends/text-to-speech/windows/windows-text-to-speech.cpp
@@ -96,12 +96,15 @@ WindowsTextToSpeechManager::~WindowsTextToSpeechManager() {
::CoUninitialize();
}
-bool WindowsTextToSpeechManager::say(Common::String str, Common::String charset) {
- if(_speechState == BROKEN || _speechState == NO_VOICE) {
+bool WindowsTextToSpeechManager::say(Common::String str, Action action, Common::String charset) {
+ if (_speechState == BROKEN || _speechState == NO_VOICE) {
warning("The tts cannot speak in this state");
return true;
}
+ if (isSpeaking() && action == DROP)
+ return true;
+
if (charset.empty()) {
#ifdef USE_TRANSLATION
charset = TransMan.getCurrentCharset();
@@ -109,19 +112,18 @@ bool WindowsTextToSpeechManager::say(Common::String str, Common::String charset)
charset = "ASCII";
#endif
}
- if (isPaused()) {
- resume();
- }
- _audio->SetState(SPAS_STOP, 0);
- _audio->SetState(SPAS_RUN, 0);
// 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));
- bool result = _voice->Speak(strW, SPF_ASYNC | SPF_PURGEBEFORESPEAK, NULL) != S_OK;
+
+ if ((isPaused() || isSpeaking()) && action == INTERRUPT)
+ stop();
+
+ bool result = _voice->Speak(strW, SPF_ASYNC, NULL) != S_OK;
free(strW);
- _speechState = SPEAKING;
+ if (!isPaused())
+ _speechState = SPEAKING;
return result;
}
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 f60a59de71..7a02c193ce 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, Common::String charset = "");
+ virtual bool say(Common::String str, Action action, Common::String charset = "");
virtual bool stop();
virtual bool pause();