diff options
author | Jaromir Wysoglad | 2019-07-11 23:38:06 +0200 |
---|---|---|
committer | Filippos Karapetis | 2019-09-01 22:47:55 +0300 |
commit | 7f895d21df5ddb7c82a2f685d3a9fcc09b3d3a7a (patch) | |
tree | 12f486bf1b1366b73967472ce8ec4312acd75a68 /backends/text-to-speech | |
parent | 8c44b032314475376e039853392292c578464091 (diff) | |
download | scummvm-rg350-7f895d21df5ddb7c82a2f685d3a9fcc09b3d3a7a.tar.gz scummvm-rg350-7f895d21df5ddb7c82a2f685d3a9fcc09b3d3a7a.tar.bz2 scummvm-rg350-7f895d21df5ddb7c82a2f685d3a9fcc09b3d3a7a.zip |
TTS: Add checks for correct TTS engine state.
Diffstat (limited to 'backends/text-to-speech')
-rw-r--r-- | backends/text-to-speech/linux/linux-text-to-speech.cpp | 45 | ||||
-rw-r--r-- | backends/text-to-speech/linux/linux-text-to-speech.h | 5 |
2 files changed, 37 insertions, 13 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 5df8f80e32..2586b16a2b 100644 --- a/backends/text-to-speech/linux/linux-text-to-speech.cpp +++ b/backends/text-to-speech/linux/linux-text-to-speech.cpp @@ -67,7 +67,7 @@ LinuxTextToSpeechManager::LinuxTextToSpeechManager() : _speechState(READY) { _connection = spd_open("ScummVM", "main", NULL, SPD_MODE_THREADED); if (_connection == 0) { - debug("couldn't open"); + _speechState = BROKEN; return; } @@ -82,12 +82,13 @@ LinuxTextToSpeechManager::LinuxTextToSpeechManager() _connection->callback_pause = speech_pause_callback; spd_set_notification_on(_connection, SPD_PAUSE); - setLanguage(Common::String("en")); + setLanguage(Common::String("cs")); updateVoices(); } LinuxTextToSpeechManager::~LinuxTextToSpeechManager() { - //spd_close(_connection); + if (_connection != 0) + spd_close(_connection); } void LinuxTextToSpeechManager::updateState(LinuxTextToSpeechManager::SpeechState state) { @@ -95,6 +96,8 @@ void LinuxTextToSpeechManager::updateState(LinuxTextToSpeechManager::SpeechState } bool LinuxTextToSpeechManager::say(Common::String str) { + if (_speechState == BROKEN) + return true; if (isSpeaking()) stop(); return spd_say(_connection, SPD_MESSAGE, str.c_str()) == -1; @@ -102,54 +105,70 @@ bool LinuxTextToSpeechManager::say(Common::String str) { } bool LinuxTextToSpeechManager::stop() { - if (_speechState == READY) - return false; + if (_speechState == READY || _speechState == BROKEN) + return true; return spd_cancel(_connection) == -1; } bool LinuxTextToSpeechManager::pause() { - if (_speechState == READY || _speechState == PAUSED) - return false; + if (_speechState == READY || _speechState == PAUSED || _speechState == BROKEN) + return true; return spd_pause(_connection) == -1; } bool LinuxTextToSpeechManager::resume() { - if (_speechState == READY || _speechState == SPEAKING) - return false; + if (_speechState == READY || _speechState == SPEAKING || _speechState == BROKEN) + return true; return spd_resume(_connection) == -1; } bool LinuxTextToSpeechManager::isSpeaking() { - if (_speechState == SPEAKING) - return true; - return false; + return _speechState == SPEAKING; +} + +bool LinuxTextToSpeechManager::isPaused() { + return _speechState == PAUSED; +} + +bool LinuxTextToSpeechManager::isReady() { + return _speechState == READY; } void LinuxTextToSpeechManager::setVoice(Common::TTSVoice *voice) { + if (_speechState == BROKEN) + return; assert(voice != nullptr && voice->getData() != nullptr); spd_set_voice_type(_connection, *(SPDVoiceType *)(voice->getData())); _ttsState->_activeVoice = voice; } void LinuxTextToSpeechManager::setRate(int rate) { + if (_speechState == BROKEN) + return; assert(rate >= -100 && rate <= 100); spd_set_voice_rate(_connection, rate); _ttsState->_rate = rate; } void LinuxTextToSpeechManager::setPitch(int pitch) { + if (_speechState == BROKEN) + return; assert(pitch >= -100 && pitch <= 100); spd_set_voice_pitch(_connection, pitch); _ttsState->_pitch = pitch; } void LinuxTextToSpeechManager::setVolume(int volume) { + if (_speechState == BROKEN) + return; assert(volume >= -100 && volume <= 100); spd_set_volume(_connection, volume); _ttsState->_volume = volume; } void LinuxTextToSpeechManager::setLanguage(Common::String language) { + if (_speechState == BROKEN) + return; spd_set_language(_connection, language.c_str()); _ttsState->_language = language; if (_ttsState->_activeVoice) @@ -157,6 +176,8 @@ void LinuxTextToSpeechManager::setLanguage(Common::String language) { } void LinuxTextToSpeechManager::updateVoices() { + if (_speechState == BROKEN) + return; /* just use these voices: SPD_MALE1, SPD_MALE2, SPD_MALE3, SPD_FEMALE1, SPD_FEMALE2, SPD_FEMALE3, 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 b0f71d33b6..bb32979dd7 100644 --- a/backends/text-to-speech/linux/linux-text-to-speech.h +++ b/backends/text-to-speech/linux/linux-text-to-speech.h @@ -35,7 +35,8 @@ public: enum SpeechState { READY, PAUSED, - SPEAKING + SPEAKING, + BROKEN }; LinuxTextToSpeechManager(); @@ -48,6 +49,8 @@ public: virtual bool resume(); virtual bool isSpeaking(); + virtual bool isPaused(); + virtual bool isReady(); virtual void setVoice(Common::TTSVoice *voice); |