GUI: U32: Use u32 for tts (MacOS)

This commit is contained in:
aryanrawlani28 2020-06-18 00:15:31 +05:30 committed by Eugene Sandulenko
parent bcbe2fe2ea
commit 0118839c59
2 changed files with 9 additions and 7 deletions

View File

@ -29,13 +29,14 @@
#include "common/text-to-speech.h"
#include "common/queue.h"
#include "common/ustr.h"
class MacOSXTextToSpeechManager : public Common::TextToSpeechManager {
public:
MacOSXTextToSpeechManager();
virtual ~MacOSXTextToSpeechManager() 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;
@ -67,7 +68,7 @@ private:
struct SpeechText {
Common::String text;
Common::String encoding;
SpeechText(const Common::String& txt, const Common::String& enc) : text(txt), encoding(enc) {}
SpeechText(const Common::String &txt, const Common::String &enc) : text(txt), encoding(enc) {}
};
Common::Queue<SpeechText> _messageQueue;
Common::String _currentSpeech;

View File

@ -81,7 +81,8 @@ MacOSXTextToSpeechManager::~MacOSXTextToSpeechManager() {
[synthesizerDelegate release];
}
bool MacOSXTextToSpeechManager::say(Common::String text, Action action, Common::String encoding) {
bool MacOSXTextToSpeechManager::say(const Common::U32String &text, Action action, Common::String encoding) {
Common::String strToSpeak = text.encode();
if (isSpeaking()) {
// Interruptions are done on word boundaries for nice transitions.
// Should we interrupt immediately?
@ -94,14 +95,14 @@ bool MacOSXTextToSpeechManager::say(Common::String text, Action action, Common::
// If the new speech is the one being currently said, continue that speech but clear the queue.
// And otherwise both clear the queue and interrupt the current speech.
_messageQueue.clear();
if (_currentSpeech == text)
if (_currentSpeech == strToSpeak)
return true;
[synthesizer stopSpeakingAtBoundary:NSSpeechWordBoundary];
} else if (action == QUEUE_NO_REPEAT) {
if (!_messageQueue.empty()) {
if (_messageQueue.back().text == text)
if (_messageQueue.back().text == strToSpeak)
return true;
} else if (_currentSpeech == text)
} else if (_currentSpeech == strToSpeak)
return true;
}
}
@ -112,7 +113,7 @@ bool MacOSXTextToSpeechManager::say(Common::String text, Action action, Common::
#endif
}
_messageQueue.push(SpeechText(text, encoding));
_messageQueue.push(SpeechText(strToSpeak, encoding));
if (!isSpeaking())
startNextSpeech();
return true;