-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSpeakMgr.cpp
295 lines (275 loc) · 8.48 KB
/
SpeakMgr.cpp
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
#include "SpeakMgr.h"
#include <QDebug>
#include "QTimer"
SpeakMgr::SpeakMgr(QObject *parent, const QString &bookname) :
QObject(parent)
{
sound = NULL;
QtSpeechTTS = NULL;
speakGoogleTTS = NULL;
speakRealPerson = NULL;
////////////////////////////////////////////////
textSpeak = "";
bookName = bookname;
speakTime = 1;
Repetitions = 0;
qDebug() << QString("发音控制器被告知的词库名为: %1").arg(bookName);
////////////////////////////////////////////////
//音频信号与槽连接
////////////////////////////////////////////////
//eSpeakTTS
sound = new SoundTread();
connect(sound,SIGNAL(soundEnded()),
this,SLOT(EmitSpeakFininshSignal()));
////////////////////////////////////////////////
//
localTTS = bcMgr->userConf->getSpeakLocalTTS();
qDebug() << QString("第三方发音引擎为:%1").arg(localTTS);
////////////////////////////////////////////////
//GoogleTTS
speakGoogleTTS = new SpeakGoogle();
connect(speakGoogleTTS,SIGNAL(soundEnded()),
this,SLOT(EmitSpeakFininshSignal()));
connect(speakGoogleTTS,SIGNAL(NetWorkUnavailable()),
this,SLOT(changeSpeakEngineToESpeak()));
connect(speakGoogleTTS,SIGNAL(speakError()),
this,SLOT(changeSpeakEngineToESpeak()));
connect(speakGoogleTTS,SIGNAL(fileOpenError()),
this,SLOT(changeSpeakEngineToESpeak()));
////////////////////////////////////////////////
//RealPerson
speakRealPerson = new SpeakReal(0,bookName);
connect(speakRealPerson,SIGNAL(soundEnded()),
this,SLOT(EmitSpeakFininshSignal()));
connect(speakRealPerson,SIGNAL(speakError()),
this,SLOT(changeSpeakEngineToESpeak()));
connect(speakRealPerson,SIGNAL(UncontionsFile()),
this,SLOT(changeSpeakEngineToESpeak()));
}
SpeakMgr::~SpeakMgr()
{
if(sound != NULL)
{
qDebug() << "~SpeakMgr清除sound";
sound->deleteLater();
sound = NULL;
}
if(QtSpeechTTS != NULL)
{
QtSpeechTTS->deleteLater();
QtSpeechTTS = NULL;
qDebug() << QString("清除QtSpeech变量成功");
}
if(speakRealPerson != NULL)
{
qDebug() << "~SpeakMgr清除speakRealPerson";
speakRealPerson->deleteLater();
speakRealPerson = NULL;
}
if(speakGoogleTTS != NULL)
{
qDebug() << "~SpeakMgr清除speakGoogleTTS";
speakGoogleTTS->deleteLater();
speakGoogleTTS = NULL;
}
}
void SpeakMgr::Speak(const QString &text,
const int &speakInterval,
const int &SpeakRepetitions)
{
///////////////////////////////////////////////////////////////
//获取发音方法配置
speakMethod = bcMgr->userConf->getSpeakMethod();
qDebug() << QString("当前配置文件所设定的默认发音方式为: %1").arg(speakMethod);
currSpeakMethod = "";
textSpeak = "";
speakTime = 1;
/////////////////////////////////////
//
textSpeak = text;
Interval = speakInterval;
Repetitions = SpeakRepetitions;
/////////////////////////////////////////
//LocalTTS
if(speakMethod == "LocalTTS")
{
qDebug() << "默认语音为:LocalTTS , 开始发音";
currSpeakMethod = "LocalTTS";
if(localTTS == QString("eSpeakTTS"))
{
qDebug() << QString("默认语音为:%1, 开始发音").arg(localTTS);
qDebug() << QString("发音次数为:%1").arg(Repetitions);
sound->getSoundTime(Repetitions);
sound->getWord(textSpeak);
sound->getTimeDiff(Interval);
sound->start();
}
else
{
QtSpeechTell();
}
}
//////////////////////////////////////////
//realSpeak&eSpeakTTS
if(speakMethod == "realSpeak&eSpeakTTS")
{
qDebug() << "默认语音为:realSpeak&eSpeakTTS , 开始发音";
qDebug() << QString("发音次数为:%1").arg(Repetitions);
currSpeakMethod = "realSpeak&eSpeakTTS";
speakRealPerson->setSoundTime(Repetitions);
speakRealPerson->setInterval(Interval);
speakRealPerson->realPersonSpeak(textSpeak);
}
//////////////////////////////////////////
//googleTTS
if(speakMethod == "googleTTS")
{
qDebug() << "默认语音为:googleTTS , 开始发音";
qDebug() << QString("发音次数为:%1").arg(Repetitions);
currSpeakMethod = "googleTTS";
speakGoogleTTS->setSoundTime(Repetitions);
speakGoogleTTS->setInterval(Interval);
speakGoogleTTS->speakGoogleTTS(textSpeak);
}
}
void SpeakMgr::Stop()
{
/////////////////////////////////////////
//LocalTTS
if(speakMethod == "LocalTTS")
{
qDebug() << "默认语音为:LocaleSpeakTTS";
if(localTTS == QString("eSpeakTTS"))
{
qDebug() << QString("停止eSpeakTTS发音");
sound->stop();
qDebug() << QString("已经停止eSpeakTTS发音");
}
else
{
qDebug() << QString("停止QtSpeechTTS发音");
QtSpeechTTS->stop();
qDebug() << QString("已经停止QtSpeechTTS发音");
}
}
//////////////////////////////////////////
//realSpeak&eSpeakTTS
if(speakMethod == "realSpeak&eSpeakTTS")
{
qDebug() << "默认语音为:realSpeak&eSpeakTTS";
qDebug() << QString("停止realSpeak&eSpeakTTS发音");
speakRealPerson->realSpeakStop();
qDebug() << QString("已经停止realSpeak&eSpeakTTS发音");
}
//////////////////////////////////////////
//googleTTS
if(speakMethod == "googleTTS")
{
qDebug() << "默认语音为:googleTTS";
qDebug() << QString("停止googleTTS发音");
speakGoogleTTS->googleTTSStop();
qDebug() << QString("已经停止googleTTS发音");
}
}
void SpeakMgr::QtSpeechTell()
{
if(QtSpeechTTS != NULL)
{
QtSpeechTTS->deleteLater();
QtSpeechTTS = NULL;
}
////////////////////////////////////////////////
//QtSpeechTTS
foreach(QtSpeech::VoiceName v, QtSpeech::voices())
{
qDebug() << "id:" << v.id;
qDebug() << "name:" << v.name;
if(v.name == localTTS)
{
qDebug() << QString("找到匹配的发音引擎:%1").arg(v.name);
QtSpeechTTS = new QtSpeech(v,this);
qDebug() << QString("建立QtSpeech变量成功");
QtSpeechTTS->setRate(bcMgr->userConf->getSpeakRate().toInt());
break;
}
}
qDebug() << QString("默认语音为:%1, 开始发音").arg(localTTS);
qDebug() << QString("发音次数为:%1").arg(Repetitions);
QtSpeechTTS->tell(textSpeak,this,SLOT(judgeSpeakTime()));
}
void SpeakMgr::changeSpeakEngineToGoogle()
{
qDebug() << "转换发音方式为:googleTTS";
currSpeakMethod = "googleTTS";
speakGoogleTTS->setSoundTime(Repetitions);
speakGoogleTTS->speakGoogleTTS(textSpeak);
}
void SpeakMgr::changeSpeakEngineToESpeak()
{
qDebug() << QString("转换发音方式为:LocalTTS");
/////////////////////////////////////////
//LocalTTS
currSpeakMethod = "LocalTTS";
if(localTTS == QString("eSpeakTTS"))
{
qDebug() << QString("默认二级发音引擎为:%1, 开始发音").arg(localTTS);
sound->getSoundTime(Repetitions);
sound->getWord(textSpeak);
sound->getTimeDiff(Interval);
sound->start();
}
else
{
QtSpeechTell();
}
}
void SpeakMgr::judgeSpeakTime()
{
if(QtSpeechTTS != NULL)
{
QtSpeechTTS->deleteLater();
QtSpeechTTS = NULL;
}
speakTime++;
qDebug() << QString("播放次数为:%1").arg(speakTime);
qDebug() << QString("发音次数为:%1").arg(Repetitions);
if(speakTime <= Repetitions)
{
////////////////////////////////
//发音次数未到
qDebug() << QString("%1发音次数未到,继续发音").arg(localTTS);
QTimer::singleShot(Interval, this, SLOT(QtSpeechTell()));
}
else
{
EmitSpeakFininshSignal();
}
}
/*
void SpeakMgr::setSpeakInterval()
{
}
void SpeakMgr::setSpeakRepetitions()
{
}
*/
void SpeakMgr::EmitSpeakFininshSignal()
{
// speakTime++;
// qDebug() << QString("播放次数为:%1").arg(speakTime);
// qDebug() << QString("发音次数为:%1").arg(Repetitions);
// if(currSpeakMethod == "LocalTTS" &&
// localTTS != QString("eSpeakTTS") &&
// speakTime <= Repetitions)
// {
////////////////////////////////
//发音次数未到
// qDebug() << QString("%1发音次数未到,继续发音").arg(localTTS);
// QtSpeechTell();
// }
// else
{
qDebug() << QString("SpeakMgr发音结束,发射发音结束信号……");
emit SpeakFininshed();
}
}