-
Notifications
You must be signed in to change notification settings - Fork 20
/
Speech.cpp
93 lines (71 loc) · 1.8 KB
/
Speech.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
#include <QDebug>
#include "Speech.h"
#include "Settings.h"
bool Speech::isSpeechEnabledForCurrentLang()
{
if(!Settings::getSpeechEnable())
{
return false;
}
QString locale;
QString selectedVoice;
int rate;
int pitch;
Settings::getSpeechInfo(Settings::getOcrLang(), locale, selectedVoice, rate, pitch);
if(selectedVoice == "<Disabled>")
{
return false;
}
return true;
}
void Speech::sayText(QString text)
{
speech->stop();
if(!Settings::getSpeechEnable())
{
return;
}
QString locale;
QString selectedVoice;
int rate;
int pitch;
Settings::getSpeechInfo(Settings::getOcrLang(), locale, selectedVoice, rate, pitch);
if(selectedVoice == "<Disabled>")
{
return;
}
speech->setLocale(locale);
auto voiceList = speech->availableVoices();
foreach (const QVoice &voice, voiceList)
{
if(voice.name() == selectedVoice)
{
speech->setVoice(voice);
}
}
speech->setVolume(Settings::getSpeechVolume() / 100.0);
speech->setRate(rate / 10.0);
speech->setPitch(pitch / 10.0);
speech->say(text);
}
void Speech::sayText(QString text, QString locale, QString selectedVoice, int volume, int rate, int pitch)
{
speech->stop();
if(selectedVoice == "<Disabled>")
{
return;
}
speech->setLocale(locale);
auto voiceList = speech->availableVoices();
foreach (const QVoice &voice, voiceList)
{
if(voice.name() == selectedVoice)
{
speech->setVoice(voice);
}
}
speech->setVolume(volume / 100.0);
speech->setRate(rate / 10.0);
speech->setPitch(pitch / 10.0);
speech->say(text);
}