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:
athrxx 2022-04-10 21:31:35 +02:00 committed by Filippos Karapetis
parent 5cba8f9242
commit eb29aea4b4
5 changed files with 26 additions and 1 deletions

View file

@ -178,7 +178,8 @@ DWORD WINAPI startSpeech(LPVOID parameters) {
bool WindowsTextToSpeechManager::say(const Common::U32String &str, Action action) {
if (_speechState == BROKEN || _speechState == NO_VOICE) {
warning("The text to speech cannot speak in this state");
if (_ttsState->_enabled)
warning("The text to speech cannot speak in this state");
return true;
}
@ -424,8 +425,14 @@ Common::String WindowsTextToSpeechManager::lcidToLocale(LCID locale) {
}
void WindowsTextToSpeechManager::updateVoices() {
if (!_ttsState->_enabled) {
_speechState = NO_VOICE;
return;
}
if (_speechState == BROKEN)
return;
_ttsState->_availableVoices.clear();
ISpObjectToken *cpVoiceToken = nullptr;
IEnumSpObjectTokens *cpEnum = nullptr;

View file

@ -82,6 +82,7 @@ TextToSpeechManager::TextToSpeechManager() {
_ttsState->_rate = 0;
_ttsState->_activeVoice = 0;
_ttsState->_language = "en";
_ttsState->_enabled = false;
_ttsState->_next = nullptr;
}
@ -93,6 +94,7 @@ void TextToSpeechManager::pushState() {
newState->_rate = _ttsState->_rate;
newState->_activeVoice = _ttsState->_activeVoice;
newState->_language = _ttsState->_language;
newState->_enabled = _ttsState->_enabled;
newState->_next = _ttsState;
_ttsState = newState;
updateVoices();
@ -115,9 +117,17 @@ bool TextToSpeechManager::popState() {
setVolume(_ttsState->_volume);
setRate(_ttsState->_rate);
setVoice(voice);
return false;
}
void TextToSpeechManager::enable(bool on) {
if (_ttsState->_enabled == on)
return;
_ttsState->_enabled = on;
updateVoices();
}
void TextToSpeechManager::clearState() {
TTSState *tmp = _ttsState;
while (tmp != nullptr) {

View file

@ -135,6 +135,7 @@ struct TTSState {
String _language;
int _activeVoice;
Array<TTSVoice> _availableVoices;
bool _enabled;
TTSState *_next;
};
@ -336,6 +337,11 @@ public:
*/
virtual void freeVoiceData(void *data) {}
/**
* Enables/disables the TTS
*/
void enable(bool on);
protected:
TTSState *_ttsState;

View file

@ -846,6 +846,7 @@ void GuiManager::initTextToSpeech() {
Common::TextToSpeechManager *ttsMan = g_system->getTextToSpeechManager();
if (ttsMan == nullptr)
return;
ttsMan->enable(ConfMan.hasKey("tts_enabled", "scummvm") ? ConfMan.getBool("tts_enabled", "scummvm") : false);
#ifdef USE_TRANSLATION
Common::String currentLanguage = TransMan.getCurrentLanguage();
ttsMan->setLanguage(currentLanguage);

View file

@ -2792,6 +2792,7 @@ void GlobalOptionsDialog::apply() {
#ifdef USE_TTS
Common::TextToSpeechManager *ttsMan = g_system->getTextToSpeechManager();
if (ttsMan) {
ttsMan->enable(_ttsCheckbox->getState());
#ifdef USE_TRANSLATION
if (newLang != oldLang) {
ttsMan->setLanguage(newLang);