-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspeech.hpp
346 lines (279 loc) · 6.78 KB
/
speech.hpp
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
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
#pragma once
#include <libsoup/soup.h>
#include <QObject>
#include <QByteArray>
#include <QString>
#include <QList>
class QTimer;
namespace Bing {
namespace Voice {
struct Font {
QString lang;
QString gender;
QString name;
};
namespace ar_EG {
extern Font Hoda;
}
namespace ar_SA {
extern Font Naayf;
}
namespace bg_BG {
extern Font Ivan;
}
namespace ca_ES {
extern Font HerenaRUS;
}
namespace cs_CZ {
extern Font Jakub;
}
namespace da_DK {
extern Font HelleRUS;
}
namespace de_AT {
extern Font Michael;
}
namespace de_CH {
extern Font Karsten;
}
namespace de_DE {
extern Font Hedda;
extern Font HeddaRUS;
extern Font StefanApollo;
}
namespace el_GR {
extern Font Stefanos;
}
namespace en_AU {
extern Font Catherine;
extern Font HayleyRUS;
}
namespace en_CA {
extern Font Linda;
extern Font HeatherRUS;
}
namespace en_GB {
extern Font SusanApollo;
extern Font HazelRUS;
extern Font GeorgeApollo;
}
namespace en_IE {
extern Font Sean;
}
namespace en_IN {
extern Font HeeraApollo;
extern Font PriyaRUS;
extern Font RaviApollo;
}
namespace en_US {
extern Font ZiraRUS;
extern Font JessaRUS;
extern Font BenjaminRUS;
}
namespace en_ES {
extern Font LauraApollo;
extern Font HelenaRUS;
extern Font PabloApollo;
}
namespace en_MX {
extern Font HildaRUS;
extern Font RaulApollo;
}
namespace fi_FI {
extern Font HeidiRUS;
}
namespace fr_CA {
extern Font Caroline;
extern Font HarmonieRUS;
}
namespace fr_CH {
extern Font Guillaume;
}
namespace fr_FR {
extern Font JulieApollo;
extern Font HortenseRUS;
extern Font PaulApollo;
}
namespace he_IL {
extern Font Asaf;
}
namespace hi_IN {
extern Font KalpanaApollo;
extern Font Kalpana;
extern Font Hemant;
}
namespace hr_HR {
extern Font Matej;
}
namespace hu_HU {
extern Font Szabolcs;
}
namespace id_ID {
extern Font Andika;
}
namespace it_IT {
extern Font CosimaApollo;
}
namespace ja_JP {
extern Font AyumiApollo;
extern Font IchiroApollo;
extern Font HarukaRUS;
extern Font LuciaRUS;
extern Font EkaterinaRUS;
}
namespace ko_KR {
extern Font HeamiRUS;
}
namespace ms_MY {
extern Font Rizwan;
}
namespace nb_NO {
extern Font HuldaRUS;
}
namespace nl_NL {
extern Font HannaRUS;
}
namespace pl_PL {
extern Font PaulinaRUS;
}
namespace pt_BR {
extern Font HeloisaRUS;
extern Font DanielApollo;
extern Font HeliaRUS;
}
namespace ro_RO {
extern Font Andrei;
}
namespace ru_RU {
extern Font IrinaApollo;
extern Font PavelApollo;
}
namespace sk_SK {
extern Font Filip;
}
namespace sl_SL {
extern Font Lado;
}
namespace sv_SE {
extern Font HedvigRUS;
}
namespace ta_IN {
extern Font Valluvar;
}
namespace th_TH {
extern Font Pattara;
}
namespace tr_TR {
extern Font SedaRUS;
}
namespace vi_VN {
extern Font An;
}
namespace zh_CN {
extern Font HuihuiRUS;
extern Font YaoyaoApollo;
extern Font KangkangApollo;
}
namespace zh_HK {
extern Font TracyApollo;
extern Font TracyRUS;
extern Font DannyApollo;
}
namespace zh_TW {
extern Font YatingApollo;
extern Font HanHanRUS;
extern Font ZhiweiApollo;
}
}
class Speech : public QObject {
Q_OBJECT
public:
static void init(int log);
static void destroy();
static Speech *instance();
/////////////////
// Recognition //
/////////////////
enum RecognitionLanguage {
ArabicEgypt = 0,
CatalanSpain,
DanishDenmark,
GermanGermany,
EnglishAustralia,
EnglishCanada,
EnglishUnitedKingdom,
EnglishIndia,
EnglishNewZealand,
EnglishUnitedStates,
SpanishSpain,
SpanishMexico,
FinnishFinland,
FrenchCanada,
FrenchFrance,
HindiIndia,
ItalianItaly,
JapaneseJapan,
KoreanKorea,
NorwegianNorway,
DutchNetherlands,
PolishPoland,
PortugueseBrazil,
PortuguesePortugal,
RussianRussia,
SwedishSweden,
ChineseChina,
ChineseHongKong,
ChineseTaiwan,
};
enum RecognitionMode {
Interactive = 0,
Dictation,
Conversation,
};
struct RecognitionResult {
double confidence;
QString lexical;
QString itn;
QString maskedItn;
QString display;
};
struct RecognitionResponse {
bool hasMatch() const;
bool isSilent() const;
void print() const;
QString recognitionStatus;
int offset;
int duration;
QList<RecognitionResult> nbest;
};
////////////////
// Synthesize //
////////////////
void authenticate(const QString &recognizerSubscriptionKey, const QString &synthesizerSubscriptionkey);
void fetchToken();
void setCache(bool cache);
void setEndpointId(const QString &endpointId);
void setTimeout(unsigned int secs);
RecognitionResponse recognize(const QByteArray &data, RecognitionLanguage language = EnglishUnitedStates, RecognitionMode mode = Interactive);
QByteArray synthesize(const QString &text, Voice::Font font = Voice::en_US::ZiraRUS);
private:
static Speech *mInstance;
static SoupSession *mSession;
static QTimer *mRenewTokenTimer;
static QString mRecognizerSubscriptionKey;
static QString mSynthesizerSubscriptionKey;
static QString mRecognizerToken;
static QString mSynthesizerToken;
static QString mConnectionId;
static QString mEndpointId;
static bool mCache;
static QString cachePath(const QString &text, const Voice::Font &font);
static QString recognitionLanguageString(RecognitionLanguage language);
RecognitionResponse parseRecognitionResponse(const QByteArray &data);
bool hasSynthesizeCache(const QString &text, const Voice::Font &font) const;
QByteArray loadSynthesizeCache(const QString &text, const Voice::Font &font);
bool saveSynthesizeCache(const QByteArray &data, const QString &text, const Voice::Font &font);
private slots:
void renewToken();
};
}