From 44687d58099527a597a5d18447cb8988b9f45763 Mon Sep 17 00:00:00 2001 From: Mikkel Krautz Date: Sun, 7 May 2017 22:12:19 +0200 Subject: TextToSpeech_unix: make setVolume not initialize speech-dispatcher. It turns out that TextToSpeech attempts to set the volume on its engines near initialization time. This made our lazy-initialization pretty much useless. This commit tries to remedy that by storing the last value passed to setVolume. It then uses that stored value the first time speech-dispatcher is initialized. As a result, we only initialize speech-dispatcher in say(), not setVolume(). --- src/mumble/TextToSpeech_unix.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src/mumble/TextToSpeech_unix.cpp') diff --git a/src/mumble/TextToSpeech_unix.cpp b/src/mumble/TextToSpeech_unix.cpp index a2e5683fc..b5e0125da 100644 --- a/src/mumble/TextToSpeech_unix.cpp +++ b/src/mumble/TextToSpeech_unix.cpp @@ -21,6 +21,9 @@ class TextToSpeechPrivate { #ifdef USE_SPEECHD protected: SPDConnection *spd; + /// Used to store the requested volume of the TextToSpeech object + /// before speech-dispatcher has been initialized. + int volume; bool initialized; void ensureInitialized(); #endif @@ -34,6 +37,7 @@ class TextToSpeechPrivate { #ifdef USE_SPEECHD TextToSpeechPrivate::TextToSpeechPrivate() { initialized = false; + volume = -1; spd = NULL; } @@ -76,6 +80,10 @@ void TextToSpeechPrivate::ensureInitialized() { } initialized = true; + + if (volume != -1) { + setVolume(volume); + } } void TextToSpeechPrivate::say(const QString &txt) { @@ -86,7 +94,10 @@ void TextToSpeechPrivate::say(const QString &txt) { } void TextToSpeechPrivate::setVolume(int vol) { - ensureInitialized(); + if (!initialized) { + volume = vol; + return; + } if (spd) spd_set_volume(spd, vol * 2 - 100); -- cgit v1.2.3