TTS: Add ttsStatus push and pop functions

This commit is contained in:
Jaromir Wysoglad 2019-07-12 00:46:42 +02:00 committed by Filippos Karapetis
parent 7f895d21df
commit 62a011e28a
4 changed files with 50 additions and 12 deletions

View File

@ -82,8 +82,9 @@ LinuxTextToSpeechManager::LinuxTextToSpeechManager()
_connection->callback_pause = speech_pause_callback;
spd_set_notification_on(_connection, SPD_PAUSE);
setLanguage(Common::String("cs"));
updateVoices();
_ttsState->_activeVoice = 0;
setLanguage(Common::String("en"));
}
LinuxTextToSpeechManager::~LinuxTextToSpeechManager() {
@ -134,12 +135,14 @@ bool LinuxTextToSpeechManager::isReady() {
return _speechState == READY;
}
void LinuxTextToSpeechManager::setVoice(Common::TTSVoice *voice) {
void LinuxTextToSpeechManager::setVoice(unsigned index) {
if (_speechState == BROKEN)
return;
assert(voice != nullptr && voice->getData() != nullptr);
spd_set_voice_type(_connection, *(SPDVoiceType *)(voice->getData()));
_ttsState->_activeVoice = voice;
debug("%d < %d", index, _ttsState->_availaibleVoices.size());
assert(index < _ttsState->_availaibleVoices.size());
Common::TTSVoice voice = _ttsState->_availaibleVoices[index];
spd_set_voice_type(_connection, *(SPDVoiceType *)(voice.getData()));
_ttsState->_activeVoice = index;
}
void LinuxTextToSpeechManager::setRate(int rate) {
@ -171,8 +174,7 @@ void LinuxTextToSpeechManager::setLanguage(Common::String language) {
return;
spd_set_language(_connection, language.c_str());
_ttsState->_language = language;
if (_ttsState->_activeVoice)
setVoice(_ttsState->_activeVoice);
setVoice(_ttsState->_activeVoice);
}
void LinuxTextToSpeechManager::updateVoices() {

View File

@ -52,7 +52,7 @@ public:
virtual bool isPaused();
virtual bool isReady();
virtual void setVoice(Common::TTSVoice *voice);
virtual void setVoice(unsigned index);
virtual void setRate(int rate);

View File

@ -30,7 +30,8 @@ TextToSpeechManager::TextToSpeechManager() {
_ttsState->_pitch = 0;
_ttsState->_volume = 0;
_ttsState->_rate = 0;
_ttsState->_activeVoice = nullptr;
_ttsState->_activeVoice = 0;
_ttsState->_language = "en";
_ttsState->_next = nullptr;
}
@ -46,5 +47,37 @@ TextToSpeechManager::~TextToSpeechManager() {
}
}
void TextToSpeechManager::pushState() {
TTSState *newState = new TTSState;
newState->_pitch = _ttsState->_pitch;
newState->_volume = _ttsState->_volume;
newState->_rate = _ttsState->_rate;
newState->_activeVoice = _ttsState->_activeVoice;
newState->_language = _ttsState->_language;
newState->_next = _ttsState;
_ttsState = newState;
updateVoices();
}
bool TextToSpeechManager::popState() {
if (_ttsState->_next == nullptr)
return true;
for (TTSVoice *i = _ttsState->_availaibleVoices.begin(); i < _ttsState->_availaibleVoices.end(); i++) {
free(i->_data);
}
TTSState *oldState = _ttsState;
_ttsState = _ttsState->_next;
delete oldState;
setLanguage(_ttsState->_language);
setPitch(_ttsState->_pitch);
setVolume(_ttsState->_volume);
setRate(_ttsState->_rate);
return false;
}
}
#endif

View File

@ -63,7 +63,7 @@ struct TTSState {
int _pitch;
int _volume;
String _language;
TTSVoice *_activeVoice;
int _activeVoice;
Array<TTSVoice> _availaibleVoices;
TTSState *_next;
};
@ -87,8 +87,8 @@ public:
virtual bool isPaused() { return false; }
virtual bool isReady() { return false; }
virtual void setVoice(TTSVoice *voice) {}
TTSVoice getVoice() { return *(_ttsState->_activeVoice); }
virtual void setVoice(unsigned index) {}
TTSVoice getVoice() { return _ttsState->_availaibleVoices[_ttsState->_activeVoice]; }
virtual void setRate(int rate) {}
int getRate() { return _ttsState->_rate; }
@ -104,6 +104,9 @@ public:
Array<TTSVoice> getVoicesArray() { return _ttsState->_availaibleVoices; }
void pushState();
bool popState();
protected:
TTSState *_ttsState;