From bf7ce38106f03c1ab79e9a7cc4599053e4f3a458 Mon Sep 17 00:00:00 2001 From: Mikkel Krautz Date: Sat, 6 May 2017 22:38:13 +0200 Subject: 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. --- src/mumble/TextToSpeech_unix.cpp | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) (limited to 'src/mumble/TextToSpeech_unix.cpp') 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); } -- cgit v1.2.3