TTS: (Windows) - implement better way to disable the option
Currently, the text-to-speech manager will try to update the voices whenever TextToSpeechManager::pushState()/popState() is called. This causes lags of 4 - 5 seconds on Windows. Also, a warning is triggered each time. This commit prevents that from happening if the tts option is not enabled. This commit currently affects only Windows. Other backends don't make use of the new _enabled setting. I don't know if it would make sense for any of these and I also wouldn't be able to test it.
This commit is contained in:
parent
5cba8f9242
commit
eb29aea4b4
5 changed files with 26 additions and 1 deletions
|
@ -178,6 +178,7 @@ DWORD WINAPI startSpeech(LPVOID parameters) {
|
||||||
|
|
||||||
bool WindowsTextToSpeechManager::say(const Common::U32String &str, Action action) {
|
bool WindowsTextToSpeechManager::say(const Common::U32String &str, Action action) {
|
||||||
if (_speechState == BROKEN || _speechState == NO_VOICE) {
|
if (_speechState == BROKEN || _speechState == NO_VOICE) {
|
||||||
|
if (_ttsState->_enabled)
|
||||||
warning("The text to speech cannot speak in this state");
|
warning("The text to speech cannot speak in this state");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -424,8 +425,14 @@ Common::String WindowsTextToSpeechManager::lcidToLocale(LCID locale) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void WindowsTextToSpeechManager::updateVoices() {
|
void WindowsTextToSpeechManager::updateVoices() {
|
||||||
|
if (!_ttsState->_enabled) {
|
||||||
|
_speechState = NO_VOICE;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (_speechState == BROKEN)
|
if (_speechState == BROKEN)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
_ttsState->_availableVoices.clear();
|
_ttsState->_availableVoices.clear();
|
||||||
ISpObjectToken *cpVoiceToken = nullptr;
|
ISpObjectToken *cpVoiceToken = nullptr;
|
||||||
IEnumSpObjectTokens *cpEnum = nullptr;
|
IEnumSpObjectTokens *cpEnum = nullptr;
|
||||||
|
|
|
@ -82,6 +82,7 @@ TextToSpeechManager::TextToSpeechManager() {
|
||||||
_ttsState->_rate = 0;
|
_ttsState->_rate = 0;
|
||||||
_ttsState->_activeVoice = 0;
|
_ttsState->_activeVoice = 0;
|
||||||
_ttsState->_language = "en";
|
_ttsState->_language = "en";
|
||||||
|
_ttsState->_enabled = false;
|
||||||
_ttsState->_next = nullptr;
|
_ttsState->_next = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,6 +94,7 @@ void TextToSpeechManager::pushState() {
|
||||||
newState->_rate = _ttsState->_rate;
|
newState->_rate = _ttsState->_rate;
|
||||||
newState->_activeVoice = _ttsState->_activeVoice;
|
newState->_activeVoice = _ttsState->_activeVoice;
|
||||||
newState->_language = _ttsState->_language;
|
newState->_language = _ttsState->_language;
|
||||||
|
newState->_enabled = _ttsState->_enabled;
|
||||||
newState->_next = _ttsState;
|
newState->_next = _ttsState;
|
||||||
_ttsState = newState;
|
_ttsState = newState;
|
||||||
updateVoices();
|
updateVoices();
|
||||||
|
@ -115,9 +117,17 @@ bool TextToSpeechManager::popState() {
|
||||||
setVolume(_ttsState->_volume);
|
setVolume(_ttsState->_volume);
|
||||||
setRate(_ttsState->_rate);
|
setRate(_ttsState->_rate);
|
||||||
setVoice(voice);
|
setVoice(voice);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TextToSpeechManager::enable(bool on) {
|
||||||
|
if (_ttsState->_enabled == on)
|
||||||
|
return;
|
||||||
|
_ttsState->_enabled = on;
|
||||||
|
updateVoices();
|
||||||
|
}
|
||||||
|
|
||||||
void TextToSpeechManager::clearState() {
|
void TextToSpeechManager::clearState() {
|
||||||
TTSState *tmp = _ttsState;
|
TTSState *tmp = _ttsState;
|
||||||
while (tmp != nullptr) {
|
while (tmp != nullptr) {
|
||||||
|
|
|
@ -135,6 +135,7 @@ struct TTSState {
|
||||||
String _language;
|
String _language;
|
||||||
int _activeVoice;
|
int _activeVoice;
|
||||||
Array<TTSVoice> _availableVoices;
|
Array<TTSVoice> _availableVoices;
|
||||||
|
bool _enabled;
|
||||||
TTSState *_next;
|
TTSState *_next;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -336,6 +337,11 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual void freeVoiceData(void *data) {}
|
virtual void freeVoiceData(void *data) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enables/disables the TTS
|
||||||
|
*/
|
||||||
|
void enable(bool on);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
TTSState *_ttsState;
|
TTSState *_ttsState;
|
||||||
|
|
||||||
|
|
|
@ -846,6 +846,7 @@ void GuiManager::initTextToSpeech() {
|
||||||
Common::TextToSpeechManager *ttsMan = g_system->getTextToSpeechManager();
|
Common::TextToSpeechManager *ttsMan = g_system->getTextToSpeechManager();
|
||||||
if (ttsMan == nullptr)
|
if (ttsMan == nullptr)
|
||||||
return;
|
return;
|
||||||
|
ttsMan->enable(ConfMan.hasKey("tts_enabled", "scummvm") ? ConfMan.getBool("tts_enabled", "scummvm") : false);
|
||||||
#ifdef USE_TRANSLATION
|
#ifdef USE_TRANSLATION
|
||||||
Common::String currentLanguage = TransMan.getCurrentLanguage();
|
Common::String currentLanguage = TransMan.getCurrentLanguage();
|
||||||
ttsMan->setLanguage(currentLanguage);
|
ttsMan->setLanguage(currentLanguage);
|
||||||
|
|
|
@ -2792,6 +2792,7 @@ void GlobalOptionsDialog::apply() {
|
||||||
#ifdef USE_TTS
|
#ifdef USE_TTS
|
||||||
Common::TextToSpeechManager *ttsMan = g_system->getTextToSpeechManager();
|
Common::TextToSpeechManager *ttsMan = g_system->getTextToSpeechManager();
|
||||||
if (ttsMan) {
|
if (ttsMan) {
|
||||||
|
ttsMan->enable(_ttsCheckbox->getState());
|
||||||
#ifdef USE_TRANSLATION
|
#ifdef USE_TRANSLATION
|
||||||
if (newLang != oldLang) {
|
if (newLang != oldLang) {
|
||||||
ttsMan->setLanguage(newLang);
|
ttsMan->setLanguage(newLang);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue