-
Notifications
You must be signed in to change notification settings - Fork 20
/
voicemanager.cpp
140 lines (84 loc) · 2.91 KB
/
voicemanager.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
#include "voicemanager.h"
#define SAFE_DELETE(pdel)if (pdel){delete pdel;}
#include <QCoreApplication>
Phonemizer* VoiceManager::LoadPhonemizer(const QString& InPhnLang,int32_t InLangNum)
{
for (Phonemizer*& Phn : Phonemizers)
{
if (Phn->GetPhnLanguage() == InPhnLang.toStdString())
return Phn;
}
Phonemizer* CreatePhn = new Phonemizer;
// Initialize regularly or minimally
CreatePhn->Initialize(QString(QCoreApplication::applicationDirPath() + "/g2p/" + InPhnLang).toStdString(),
InLangNum == ETTSLanguageType::Char);
CreatePhn->SetPhnLanguage(InPhnLang.toStdString());
Phonemizers.push_back(CreatePhn);
return Phonemizers[Phonemizers.size() - 1];
}
ESpeakPhonemizer *VoiceManager::LoadESpeakPhonemizer(const QString &InVoiceName)
{
for (ESpeakPhonemizer*& Phn : ENGPhonemizers)
{
if (Phn->GetVoiceName() == InVoiceName.toStdString())
return Phn;
}
ESpeakPhonemizer* CreatePhn = new ESpeakPhonemizer;
CreatePhn->Initialize(QString(QCoreApplication::applicationDirPath() + "/g2p/eSpeak-NG").toStdString()
,InVoiceName.toStdString());
ENGPhonemizers.push_back(CreatePhn);
return CreatePhn;
}
size_t VoiceManager::LoadVoice(const QString &Voname)
{
Voice* NuVoice = new Voice(QString(QCoreApplication::applicationDirPath() + "/models/" + Voname).toStdString(),Voname.toStdString(),nullptr);
QString PLang = QString::fromStdString(NuVoice->GetInfo().s_Language_Fullname);
Phonemizer* Phon = LoadPhonemizer(PLang,NuVoice->GetInfo().LangType);
ESpeakPhonemizer* ENG_Phon = nullptr;
if (NuVoice->GetInfo().s_eSpeakLang.size()){
ENG_Phon = LoadESpeakPhonemizer(QString::fromStdString(NuVoice->GetInfo().s_eSpeakLang));
}
NuVoice->AddPhonemizer(Phon,ENG_Phon);
std::string NumTxtPath = QString(QCoreApplication::applicationDirPath() + "/num2txt/" +
QString::fromStdString(NuVoice->GetInfo().s_Language) + ".sor").toStdString();
NuVoice->LoadNumberText(NumTxtPath);
Voices.push_back(NuVoice);
Voices[Voices.size() - 1]->SetDictEntries(ManDict);
return Voices.size() - 1;
}
int VoiceManager::FindVoice(const QString &inName, bool autoload)
{
for (size_t i = 0; i < Voices.size();i++)
{
if (Voices[i]->Name == inName.toStdString())
return (int)i;
}
if (autoload)
return (int)LoadVoice(inName);
else
return -1;
}
Voice *VoiceManager::operator[](size_t in)
{
return Voices[in];
}
void VoiceManager::SetDict(const std::vector<DictEntry> &InDict)
{
ManDict = InDict;
}
VoiceManager::VoiceManager()
{
}
VoiceManager::~VoiceManager()
{
for (Phonemizer* Phni : Phonemizers)
{
SAFE_DELETE(Phni)
}
for (Voice* Vo : Voices)
{
SAFE_DELETE(Vo)
}
Voices.clear();
Phonemizers.clear();
}