diff options
-rw-r--r-- | backends/text-to-speech/linux/linux-text-to-speech.cpp | 7 | ||||
-rw-r--r-- | backends/text-to-speech/linux/linux-text-to-speech.h | 2 | ||||
-rw-r--r-- | backends/text-to-speech/windows/windows-text-to-speech.cpp | 22 | ||||
-rw-r--r-- | backends/text-to-speech/windows/windows-text-to-speech.h | 2 | ||||
-rw-r--r-- | common/text-to-speech.h | 17 |
5 files changed, 35 insertions, 15 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(); diff --git a/common/text-to-speech.h b/common/text-to-speech.h index 004de3116b..b776a1cae3 100644 --- a/common/text-to-speech.h +++ b/common/text-to-speech.h @@ -136,6 +136,11 @@ struct TTSState { */ class TextToSpeechManager { public: + enum Action { + INTERRUPT, + QUEUE, + DROP + }; /** * The constructor sets the language to the translation manager language if * USE_TRANSLATION is defined, or english when it isn't defined. It sets the rate, @@ -145,13 +150,23 @@ public: virtual ~TextToSpeechManager(); /** + * Interrupts what's being said and says the given string + * + * @param str The string to say + * @param charset The encoding of the string. If empty this is assumed to be the + * encoding used for the GUI. + */ + virtual bool say(String str, String charset = "") { return say(str, INTERRUPT, charset); } + + /** * Says the given string * * @param str The string to say + * @param action What to do if another string is just being said. * @param charset The encoding of the string. If empty this is assumed to be the * encoding used for the GUI. */ - virtual bool say(String str, String charset = "") { return false; } + virtual bool say(String str, Action action, String charset = "") { return false; } /** * Stops the speech |