From ef7ec444d31c140b4746215dcc5f86be6d47f0b3 Mon Sep 17 00:00:00 2001 From: aryanrawlani28 Date: Wed, 17 Jun 2020 23:59:45 +0530 Subject: [PATCH] GUI: U32: Enable u32 for tts (Windows) They always take in U32 strings now. - Revert tts descriptions to string, they don't use translations, so better to keep it as strings. - Make read() take in const U32 references. --- .../windows/windows-text-to-speech.cpp | 8 +++-- .../windows/windows-text-to-speech.h | 3 +- common/text-to-speech.cpp | 4 +-- common/text-to-speech.h | 10 +++---- engines/testbed/speech.cpp | 30 +++++++++---------- gui/Tooltip.cpp | 2 +- gui/widget.cpp | 2 +- gui/widget.h | 4 +-- gui/widgets/list.cpp | 2 +- gui/widgets/popup.cpp | 4 +-- gui/widgets/popup.h | 4 +-- gui/widgets/tab.cpp | 2 +- 12 files changed, 39 insertions(+), 36 deletions(-) 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 09e4239487b..d52014b3db7 100644 --- a/backends/text-to-speech/windows/windows-text-to-speech.cpp +++ b/backends/text-to-speech/windows/windows-text-to-speech.cpp @@ -174,7 +174,7 @@ DWORD WINAPI startSpeech(LPVOID parameters) { return 0; } -bool WindowsTextToSpeechManager::say(Common::String str, Action action, Common::String charset) { +bool WindowsTextToSpeechManager::say(const Common::U32String &str, Action action, Common::String charset) { if (_speechState == BROKEN || _speechState == NO_VOICE) { warning("The text to speech cannot speak in this state"); return true; @@ -191,10 +191,12 @@ bool WindowsTextToSpeechManager::say(Common::String str, Action action, Common:: #endif } + Common::String strToSpeak = str.encode(); + // We have to set the pitch by prepending xml code at the start of the said string; Common::String pitch = Common::String::format("", _ttsState->_pitch / 10); - str.replace((uint32)0, 0, pitch); - WCHAR *strW = (WCHAR *) Common::Encoding::convert("UTF-16", charset, str.c_str(), str.size()); + strToSpeak.replace((uint32)0, 0, pitch); + WCHAR *strW = (WCHAR *) Common::Encoding::convert("UTF-16", charset, strToSpeak.c_str(), strToSpeak.size()); if (strW == nullptr) { warning("Cannot convert from %s encoding for text to speech", charset.c_str()); return true; 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 7f52549a5f5..ac0906117a0 100644 --- a/backends/text-to-speech/windows/windows-text-to-speech.h +++ b/backends/text-to-speech/windows/windows-text-to-speech.h @@ -29,6 +29,7 @@ #include "common/text-to-speech.h" #include "common/str.h" +#include "common/ustr.h" #include "common/list.h" @@ -51,7 +52,7 @@ public: WindowsTextToSpeechManager(); virtual ~WindowsTextToSpeechManager() override; - virtual bool say(Common::String str, Action action, Common::String charset = "") override; + virtual bool say(const Common::U32String &str, Action action, Common::String charset = "") override; virtual bool stop() override; virtual bool pause() override; diff --git a/common/text-to-speech.cpp b/common/text-to-speech.cpp index 074ff7b819f..8e4742b3e99 100644 --- a/common/text-to-speech.cpp +++ b/common/text-to-speech.cpp @@ -31,12 +31,12 @@ TTSVoice::TTSVoice() : _gender(UNKNOWN_GENDER) , _age(UNKNOWN_AGE) , _data(nullptr) - , _description(Common::U32String("")) { + , _description("") { _refCount = new int; *_refCount = 1; } -TTSVoice::TTSVoice(Gender gender, Age age, void *data, U32String description) +TTSVoice::TTSVoice(Gender gender, Age age, void *data, String description) : _gender(gender) , _age(age) , _data(data) diff --git a/common/text-to-speech.h b/common/text-to-speech.h index a237ddb7490..62aa953bf78 100644 --- a/common/text-to-speech.h +++ b/common/text-to-speech.h @@ -53,7 +53,7 @@ class TTSVoice { public: TTSVoice(); - TTSVoice(Gender gender, Age age, void *data, U32String description) ; + TTSVoice(Gender gender, Age age, void *data, String description) ; TTSVoice(const TTSVoice& voice); @@ -111,13 +111,13 @@ class TTSVoice { * Returns the voice description. This description is really tts engine * specific and might be not be available with some tts engines. */ - U32String getDescription() { return _description; }; + String getDescription() { return _description; }; protected: Gender _gender; ///< Gender of the voice Age _age; ///< Age of the voice void *_data; ///< Pointer to tts engine specific data about the voice - U32String _description; ///< Description of the voice (gets displayed in GUI) + String _description; ///< Description of the voice (gets displayed in GUI) int *_refCount; ///< Reference count (serves for proper feeing of _data) }; @@ -158,7 +158,7 @@ public: * @param charset The encoding of the string. If empty this is assumed to be the * encoding used for the GUI. */ - bool say(U32String str, String charset = "") { return say(str.encode(), INTERRUPT_NO_REPEAT, charset); } + bool say(const U32String &str, String charset = "") { return say(str, INTERRUPT_NO_REPEAT, charset); } /** * Says the given string @@ -178,7 +178,7 @@ public: * @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, Action action, String charset = "") { return false; } + virtual bool say(const U32String &str, Action action, String charset = "") { return false; } /** * Stops the speech diff --git a/engines/testbed/speech.cpp b/engines/testbed/speech.cpp index 1d9622abe62..056207efc6e 100644 --- a/engines/testbed/speech.cpp +++ b/engines/testbed/speech.cpp @@ -208,7 +208,7 @@ TestExitStatus Speechtests::testPauseResume() { Testsuite::logDetailedPrintf("TTS pause failed\n"); return kTestFailed; } - ttsMan->say("and then resume again", Common::TextToSpeechManager::QUEUE); + ttsMan->say(Common::convertToU32String("and then resume again"), Common::TextToSpeechManager::QUEUE); g_system->delayMillis(3000); if (!ttsMan->isPaused()) { Testsuite::logDetailedPrintf("TTS pause failed\n"); @@ -398,7 +398,7 @@ TestExitStatus Speechtests::testQueueing() { } ttsMan->say(Common::convertToU32String("This is first speech.")); - ttsMan->say("This is second speech.", Common::TextToSpeechManager::QUEUE); + ttsMan->say(Common::convertToU32String("This is second speech."), Common::TextToSpeechManager::QUEUE); waitForSpeechEnd(ttsMan); Common::String prompt = "Did you hear a voice saying: \"This is first speech. This is second speech\" ?"; if (!Testsuite::handleInteractiveInput(prompt, "Yes", "No", kOptionLeft)) { @@ -428,7 +428,7 @@ TestExitStatus Speechtests::testInterrupting() { ttsMan->say(Common::convertToU32String("A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z")); g_system->delayMillis(1000); - ttsMan->say("Speech interrupted", Common::TextToSpeechManager::INTERRUPT); + ttsMan->say(Common::convertToU32String("Speech interrupted"), Common::TextToSpeechManager::INTERRUPT); waitForSpeechEnd(ttsMan); Common::String prompt = "Did you hear a voice saying the engilsh alphabet, but it got interrupted and said: \"Speech interrupted\" instead?"; if (!Testsuite::handleInteractiveInput(prompt, "Yes", "No", kOptionLeft)) { @@ -457,7 +457,7 @@ TestExitStatus Speechtests::testDroping() { } ttsMan->say(Common::convertToU32String("Today is a really nice weather, perfect day to use ScummVM, don't you think?")); - ttsMan->say("Speech interrupted, fail", Common::TextToSpeechManager::DROP); + ttsMan->say(Common::convertToU32String("Speech interrupted, fail"), Common::TextToSpeechManager::DROP); waitForSpeechEnd(ttsMan); Common::String prompt = "Did you hear a voice say: \"Today is a really nice weather, perfect day to use ScummVM, don't you think?\" and nothing else?"; if (!Testsuite::handleInteractiveInput(prompt, "Yes", "No", kOptionLeft)) { @@ -486,15 +486,15 @@ TestExitStatus Speechtests::testInterruptNoRepeat() { } ttsMan->say(Common::convertToU32String("This is the first sentence, this should get interrupted")); - ttsMan->say("Failure", Common::TextToSpeechManager::QUEUE); + ttsMan->say(Common::convertToU32String("Failure"), Common::TextToSpeechManager::QUEUE); g_system->delayMillis(1000); - ttsMan->say("This is the second sentence, it should play only once", Common::TextToSpeechManager::INTERRUPT_NO_REPEAT); - ttsMan->say("Failure", Common::TextToSpeechManager::QUEUE); + ttsMan->say(Common::convertToU32String("This is the second sentence, it should play only once"), Common::TextToSpeechManager::INTERRUPT_NO_REPEAT); + ttsMan->say(Common::convertToU32String("Failure"), Common::TextToSpeechManager::QUEUE); g_system->delayMillis(1000); - ttsMan->say("This is the second sentence, it should play only once", Common::TextToSpeechManager::INTERRUPT_NO_REPEAT); - ttsMan->say("Failure", Common::TextToSpeechManager::QUEUE); + ttsMan->say(Common::convertToU32String("This is the second sentence, it should play only once"), Common::TextToSpeechManager::INTERRUPT_NO_REPEAT); + ttsMan->say(Common::convertToU32String("Failure"), Common::TextToSpeechManager::QUEUE); g_system->delayMillis(1000); - ttsMan->say("This is the second sentence, it should play only once", Common::TextToSpeechManager::INTERRUPT_NO_REPEAT); + ttsMan->say(Common::convertToU32String("This is the second sentence, it should play only once"), Common::TextToSpeechManager::INTERRUPT_NO_REPEAT); waitForSpeechEnd(ttsMan); Common::String prompt = "Did you hear a voice say: \"This is the first sentence, this should get interrupted\", but it got interrupted and \"This is the second sentence, it should play only once.\" got said instead?"; if (!Testsuite::handleInteractiveInput(prompt, "Yes", "No", kOptionLeft)) { @@ -523,13 +523,13 @@ TestExitStatus Speechtests::testQueueNoRepeat() { } ttsMan->say(Common::convertToU32String("This is the first sentence.")); - ttsMan->say("This is the first sentence.", Common::TextToSpeechManager::QUEUE_NO_REPEAT); + ttsMan->say(Common::convertToU32String("This is the first sentence."), Common::TextToSpeechManager::QUEUE_NO_REPEAT); g_system->delayMillis(1000); - ttsMan->say("This is the first sentence.", Common::TextToSpeechManager::QUEUE_NO_REPEAT); - ttsMan->say("This is the second sentence.", Common::TextToSpeechManager::QUEUE_NO_REPEAT); - ttsMan->say("This is the second sentence.", Common::TextToSpeechManager::QUEUE_NO_REPEAT); + ttsMan->say(Common::convertToU32String("This is the first sentence."), Common::TextToSpeechManager::QUEUE_NO_REPEAT); + ttsMan->say(Common::convertToU32String("This is the second sentence."), Common::TextToSpeechManager::QUEUE_NO_REPEAT); + ttsMan->say(Common::convertToU32String("This is the second sentence."), Common::TextToSpeechManager::QUEUE_NO_REPEAT); g_system->delayMillis(1000); - ttsMan->say("This is the second sentence.", Common::TextToSpeechManager::QUEUE_NO_REPEAT); + ttsMan->say(Common::convertToU32String("This is the second sentence."), Common::TextToSpeechManager::QUEUE_NO_REPEAT); waitForSpeechEnd(ttsMan); Common::String prompt = "Did you hear a voice say: \"This is the first sentence. This the second sentence\" and nothing else?"; if (!Testsuite::handleInteractiveInput(prompt, "Yes", "No", kOptionLeft)) { diff --git a/gui/Tooltip.cpp b/gui/Tooltip.cpp index 4e32b175df8..9c8a8946423 100644 --- a/gui/Tooltip.cpp +++ b/gui/Tooltip.cpp @@ -64,7 +64,7 @@ void Tooltip::setup(Dialog *parent, Widget *widget, int x, int y) { Common::TextToSpeechManager *ttsMan = g_system->getTextToSpeechManager(); if (ttsMan == nullptr) return; - ttsMan->say(Common::convertFromU32String(widget->getTooltip()), Common::TextToSpeechManager::QUEUE_NO_REPEAT); + ttsMan->say(widget->getTooltip(), Common::TextToSpeechManager::QUEUE_NO_REPEAT); } #endif } diff --git a/gui/widget.cpp b/gui/widget.cpp index 2a568615438..9499676ba93 100644 --- a/gui/widget.cpp +++ b/gui/widget.cpp @@ -277,7 +277,7 @@ Common::U32String Widget::cleanupHotkey(const Common::U32String &label) { return Common::U32String(res); } -void Widget::read(Common::U32String str) { +void Widget::read(const Common::U32String &str) { #ifdef USE_TTS if (ConfMan.hasKey("tts_enabled", "scummvm") && ConfMan.getBool("tts_enabled", "scummvm")) { diff --git a/gui/widget.h b/gui/widget.h index c7e805d70f9..66e313cf503 100644 --- a/gui/widget.h +++ b/gui/widget.h @@ -175,7 +175,7 @@ public: virtual bool containsWidget(Widget *) const { return false; } - void read(Common::U32String str); + void read(const Common::U32String &str); protected: void updateState(int oldFlags, int newFlags); @@ -208,7 +208,7 @@ public: const Common::U32String &getLabel() const { return _label; } void setAlign(Graphics::TextAlign align); Graphics::TextAlign getAlign() const { return _align; } - void readLabel() { read(Common::convertFromU32String(_label)); } + void readLabel() { read(_label); } protected: void drawWidget() override; diff --git a/gui/widgets/list.cpp b/gui/widgets/list.cpp index da7e8f1bf4b..c0b1d1c4d53 100644 --- a/gui/widgets/list.cpp +++ b/gui/widgets/list.cpp @@ -287,7 +287,7 @@ void ListWidget::handleMouseMoved(int x, int y, int button) { if (item != -1) { if(_lastRead != item) { - read(Common::convertFromU32String(_dataList[item])); + read(_dataList[item]); _lastRead = item; } } diff --git a/gui/widgets/popup.cpp b/gui/widgets/popup.cpp index 374d862c279..fa30fb73ea4 100644 --- a/gui/widgets/popup.cpp +++ b/gui/widgets/popup.cpp @@ -190,7 +190,7 @@ void PopUpDialog::handleMouseMoved(int x, int y, int button) { // ...and update the selection accordingly setSelection(item); if (_lastRead != item && _entries.size() > 0 && item != -1) { - read(Common::convertFromU32String(_entries[item])); + read(_entries[item]); _lastRead = item; } } @@ -199,7 +199,7 @@ void PopUpDialog::handleMouseLeft(int button) { _lastRead = -1; } -void PopUpDialog::read(Common::U32String str) { +void PopUpDialog::read(const Common::U32String &str) { #ifdef USE_TTS if (ConfMan.hasKey("tts_enabled", "scummvm") && ConfMan.getBool("tts_enabled", "scummvm")) { diff --git a/gui/widgets/popup.h b/gui/widgets/popup.h index 2dec77793e7..732593b93e8 100644 --- a/gui/widgets/popup.h +++ b/gui/widgets/popup.h @@ -78,7 +78,7 @@ public: uint32 getSelectedTag() const { return (_selectedItem >= 0) ? _entries[_selectedItem].tag : (uint32)-1; } // const String& getSelectedString() const { return (_selectedItem >= 0) ? _entries[_selectedItem].name : String::emptyString; } - void handleMouseEntered(int button) override { if (_selectedItem != -1) read(Common::convertFromU32String(_entries[_selectedItem].name)); setFlags(WIDGET_HILITED); markAsDirty(); } + void handleMouseEntered(int button) override { if (_selectedItem != -1) read(_entries[_selectedItem].name); setFlags(WIDGET_HILITED); markAsDirty(); } void handleMouseLeft(int button) override { clearFlags(WIDGET_HILITED); markAsDirty(); } void reflowLayout() override; @@ -140,7 +140,7 @@ protected: void moveUp(); void moveDown(); - void read(Common::U32String); + void read(const Common::U32String &str); }; } // End of namespace GUI diff --git a/gui/widgets/tab.cpp b/gui/widgets/tab.cpp index 645e7110c78..b9ea2f960fb 100644 --- a/gui/widgets/tab.cpp +++ b/gui/widgets/tab.cpp @@ -260,7 +260,7 @@ void TabWidget::handleMouseMoved(int x, int y, int button) { if (tabID <= _lastVisibleTab) { if (tabID != _lastRead) { - read(Common::convertFromU32String(_tabs[tabID].title)); + read(_tabs[tabID].title); _lastRead = tabID; } }