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.
This commit is contained in:
aryanrawlani28 2020-06-17 23:59:45 +05:30 committed by Eugene Sandulenko
parent d4d5b8906e
commit ef7ec444d3
12 changed files with 39 additions and 36 deletions

View File

@ -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("<pitch absmiddle=\"%d\">", _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;

View File

@ -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;

View File

@ -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)

View File

@ -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

View File

@ -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)) {

View File

@ -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
}

View File

@ -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")) {

View File

@ -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;

View File

@ -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;
}
}

View File

@ -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")) {

View File

@ -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

View File

@ -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;
}
}