diff options
author | Mikkel Krautz <mikkel@krautz.dk> | 2017-05-06 23:38:13 +0300 |
---|---|---|
committer | Mikkel Krautz <mikkel@krautz.dk> | 2017-05-07 23:01:40 +0300 |
commit | bf7ce38106f03c1ab79e9a7cc4599053e4f3a458 (patch) | |
tree | 7a08dfc1548cd6ccfdb57418e37a288c8f83113f /src/mumble/TextToSpeech_unix.cpp | |
parent | 81b00bfc76d1bf322743d7cc238e28da7dfc7c5c (diff) |
TextToSpeech_unix: lazily initialize speech-dispatcher.
This commit should ensure that Mumble does not spawn
instances of the speech-dispatcher daemon for users that do not
use Text-to-Speech.
Diffstat (limited to 'src/mumble/TextToSpeech_unix.cpp')
-rw-r--r-- | src/mumble/TextToSpeech_unix.cpp | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/src/mumble/TextToSpeech_unix.cpp b/src/mumble/TextToSpeech_unix.cpp index 971baca24..a2e5683fc 100644 --- a/src/mumble/TextToSpeech_unix.cpp +++ b/src/mumble/TextToSpeech_unix.cpp @@ -21,6 +21,8 @@ class TextToSpeechPrivate { #ifdef USE_SPEECHD protected: SPDConnection *spd; + bool initialized; + void ensureInitialized(); #endif public: TextToSpeechPrivate(); @@ -31,6 +33,22 @@ class TextToSpeechPrivate { #ifdef USE_SPEECHD TextToSpeechPrivate::TextToSpeechPrivate() { + initialized = false; + spd = NULL; +} + +TextToSpeechPrivate::~TextToSpeechPrivate() { + if (spd) { + spd_close(spd); + spd = NULL; + } +} + +void TextToSpeechPrivate::ensureInitialized() { + if (initialized) { + return; + } + spd = spd_open("Mumble", NULL, NULL, SPD_MODE_THREADED); if (! spd) { qWarning("TextToSpeech: Failed to contact speech dispatcher."); @@ -56,21 +74,20 @@ TextToSpeechPrivate::TextToSpeechPrivate() { if (spd_set_spelling(spd, SPD_SPELL_ON) != 0) qWarning("TextToSpeech: Failed to set spelling mode."); } -} -TextToSpeechPrivate::~TextToSpeechPrivate() { - if (spd) { - spd_close(spd); - spd = NULL; - } + initialized = true; } void TextToSpeechPrivate::say(const QString &txt) { + ensureInitialized(); + if (spd) spd_say(spd, SPD_MESSAGE, txt.toUtf8()); } void TextToSpeechPrivate::setVolume(int vol) { + ensureInitialized(); + if (spd) spd_set_volume(spd, vol * 2 - 100); } |