-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSpeakTTS.cpp
75 lines (62 loc) · 1.96 KB
/
SpeakTTS.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
#include "SpeakTTS.h"
SpeakTTS::SpeakTTS(QObject *parent) :
QObject(parent)
{
}
void SpeakTTS::initESpeaktts()
{
espeak_Initialize(AUDIO_OUTPUT_SYNCH_PLAYBACK, 0, "./eSpeak/", 0);
//espeak_SetSynthCallback(SynthCallback); // ÉèÖûص÷º¯Êý
}
void SpeakTTS::setSpeakSpeed(const int &speed)
{
//////////////////////////////////////////////////////////////////////
//espeakRATE: speaking speed in word per minute.
//Values 80 to 450.
espeak_SetParameter(espeakRATE,speed,0);
}
void SpeakTTS::setSpeakVolume(const int &volume)
{
/////////////////////////////////////////////////////////////////////
//espeakVOLUME: volume in range 0-200 or more.
//0=silence, 100=normal full volume,
//greater values may produce amplitude compression or distortion
espeak_SetParameter(espeakVOLUME,volume,0);
}
void SpeakTTS::setSpeakPitch(const int &pitch, const int &range)
{
/////////////////////////////////////////////////////////////////////
//espeakPITCH: base pitch, range 0-100. 50=normal
//espeakRANGE: pitch range, range 0-100. 0-monotone, 50=normal
espeak_SetParameter(espeakPITCH,pitch,0);
espeak_SetParameter(espeakRANGE,range,0);
}
void SpeakTTS::setSpeakWordGap(const int &wordgap)
{
///////////////////////////////////////////////////////////////////////////
//espeakWORDGAP: pause between words, units of 10mS (at the default speed)
espeak_SetParameter(espeakWORDGAP,wordgap,0);
}
void SpeakTTS::setSpeakLanguage(const char *language)
{
espeak_SetVoiceByName(language);
}
void SpeakTTS::speakTTS(const QString &text)
{
QByteArray byteArray = text.toLatin1();
const char *word = byteArray.constData();
espeak_Synth(word, 0, 0, POS_CHARACTER, 0, espeakCHARS_UTF8, NULL ,NULL);
espeak_Synchronize();
espeak_Terminate();
}
bool SpeakTTS::isSpeakTTSPlaying()
{
return espeak_IsPlaying();
}
void SpeakTTS::stopSpeakTTS()
{
if(espeak_IsPlaying())
{
espeak_Cancel();
}
}