Skip to content
Permalink
Browse files

Merge PR #3071: TextToSpeech_unix: lazy initialize speech-dispatcher.

  • Loading branch information...
mkrautz committed May 8, 2017
2 parents c0c5ba7 + 44687d5 commit d3470c30bbc2e3c8cd8622bf1d91cf78bf57f71f
Showing with 33 additions and 5 deletions.
  1. +33 −5 src/mumble/TextToSpeech_unix.cpp
@@ -21,6 +21,11 @@ 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
public:
TextToSpeechPrivate();
@@ -31,6 +36,23 @@ class TextToSpeechPrivate {

#ifdef USE_SPEECHD
TextToSpeechPrivate::TextToSpeechPrivate() {
initialized = false;
volume = -1;
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 +78,27 @@ 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;

if (volume != -1) {
setVolume(volume);
}
}

void TextToSpeechPrivate::say(const QString &txt) {
ensureInitialized();

if (spd)
spd_say(spd, SPD_MESSAGE, txt.toUtf8());
}

void TextToSpeechPrivate::setVolume(int vol) {
if (!initialized) {
volume = vol;
return;
}

if (spd)
spd_set_volume(spd, vol * 2 - 100);
}

0 comments on commit d3470c3

Please sign in to comment.
You can’t perform that action at this time.