aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--backends/text-to-speech/linux/linux-text-to-speech.cpp16
-rw-r--r--backends/text-to-speech/linux/linux-text-to-speech.h2
-rw-r--r--common/text-to-speech.cpp35
-rw-r--r--common/text-to-speech.h9
4 files changed, 50 insertions, 12 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 2586b16a2b..02ca5a8ef8 100644
--- a/backends/text-to-speech/linux/linux-text-to-speech.cpp
+++ b/backends/text-to-speech/linux/linux-text-to-speech.cpp
@@ -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() {
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 bb32979dd7..85f53eb2f8 100644
--- a/backends/text-to-speech/linux/linux-text-to-speech.h
+++ b/backends/text-to-speech/linux/linux-text-to-speech.h
@@ -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);
diff --git a/common/text-to-speech.cpp b/common/text-to-speech.cpp
index 1e2456d8a6..459d4706db 100644
--- a/common/text-to-speech.cpp
+++ b/common/text-to-speech.cpp
@@ -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
diff --git a/common/text-to-speech.h b/common/text-to-speech.h
index 4bb81118bf..2c9b5c7778 100644
--- a/common/text-to-speech.h
+++ b/common/text-to-speech.h
@@ -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;