Welcome to mirror list, hosted at ThFree Co, Russian Federation.

TextToSpeech_unix.cpp « mumble « src - github.com/mumble-voip/mumble.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: df3fc86425501c7544d732e5855b4907565346a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// Copyright 2005-2016 The Mumble Developers. All rights reserved.
// Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file at the root of the
// Mumble source tree or at <https://www.mumble.info/LICENSE>.

#include "mumble_pch.hpp"

#include "TextToSpeech.h"

#ifdef USE_SPEECHD
# ifdef USE_SPEECHD_PKGCONFIG
#  include <speech-dispatcher/libspeechd.h>
# else
#  include <libspeechd.h>
# endif
#endif

#include "Global.h"

class TextToSpeechPrivate {
#ifdef USE_SPEECHD
	protected:
		SPDConnection *spd;
#endif
	public:
		TextToSpeechPrivate();
		~TextToSpeechPrivate();
		void say(const QString &text);
		void setVolume(int v);
};

#ifdef USE_SPEECHD
TextToSpeechPrivate::TextToSpeechPrivate() {
	spd = spd_open("Mumble", NULL, NULL, SPD_MODE_THREADED);
	if (! spd) {
		qWarning("TextToSpeech: Failed to contact speech dispatcher.");
	} else {
		QString lang;
		if (!g.s.qsTTSLanguage.isEmpty()) {
			lang = g.s.qsTTSLanguage;
		} else if (!g.s.qsLanguage.isEmpty()) {
			QLocale locale(g.s.qsLanguage);
			lang = locale.bcp47Name();
		} else {
			QLocale systemLocale;
			lang = systemLocale.bcp47Name();
		}
		if (!lang.isEmpty()) {
			if (spd_set_language(spd, lang.toLocal8Bit().constData()) != 0) {
				qWarning("TextToSpeech: Failed to set language.");
			}
		}

		if (spd_set_punctuation(spd, SPD_PUNCT_NONE) != 0)
			qWarning("TextToSpech: Failed to set punctuation mode.");
		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;
	}
}

void TextToSpeechPrivate::say(const QString &txt) {
	if (spd)
		spd_say(spd, SPD_MESSAGE, txt.toUtf8());
}

void TextToSpeechPrivate::setVolume(int vol) {
	if (spd)
		spd_set_volume(spd, vol * 2 - 100);
}
#else
TextToSpeechPrivate::TextToSpeechPrivate() {
	qWarning("TextToSpeech: Compiled without support for speech-dispatcher");
}

TextToSpeechPrivate::~TextToSpeechPrivate() {
}

void TextToSpeechPrivate::say(const QString &) {
}

void TextToSpeechPrivate::setVolume(int) {
}
#endif


TextToSpeech::TextToSpeech(QObject *p) : QObject(p) {
	enabled = true;
	d = new TextToSpeechPrivate();
}

TextToSpeech::~TextToSpeech() {
	delete d;
}

void TextToSpeech::say(const QString &text) {
	if (enabled)
		d->say(text);
}

void TextToSpeech::setEnabled(bool e) {
	enabled = e;
}

void TextToSpeech::setVolume(int volume) {
	d->setVolume(volume);
}


bool TextToSpeech::isEnabled() const {
	return enabled;
}