Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
TensorSpeech
GitHub Repository: TensorSpeech/TensorFlowTTS
Path: blob/master/examples/cppwin/TensorflowTTSCppInference/EnglishPhoneticProcessor.cpp
1559 views
1
#include "EnglishPhoneticProcessor.h"
2
#include "VoxCommon.hpp"
3
4
using namespace std;
5
6
bool EnglishPhoneticProcessor::Initialize(Phonemizer* InPhn)
7
{
8
9
10
Phoner = InPhn;
11
Tokenizer.SetAllowedChars(Phoner->GetGraphemeChars());
12
13
14
15
return true;
16
}
17
18
std::string EnglishPhoneticProcessor::ProcessTextPhonetic(const std::string& InText, const std::vector<string> &InPhonemes,ETTSLanguage::Enum InLanguage)
19
{
20
if (!Phoner)
21
return "ERROR";
22
23
24
25
vector<string> Words = Tokenizer.Tokenize(InText,InLanguage);
26
27
string Assemble = "";
28
// Make a copy of the dict passed.
29
30
for (size_t w = 0; w < Words.size();w++)
31
{
32
const string& Word = Words[w];
33
34
if (Word.find("@") != std::string::npos){
35
std::string AddPh = Word.substr(1); // Remove the @
36
size_t OutId = 0;
37
if (VoxUtil::FindInVec(AddPh,InPhonemes,OutId))
38
{
39
Assemble.append(InPhonemes[OutId]);
40
Assemble.append(" ");
41
42
43
}
44
45
continue;
46
47
}
48
49
50
51
52
size_t OverrideIdx = 0;
53
54
55
56
std::string Res = Phoner->ProcessWord(Word,0.001f);
57
58
// Cache the word in the override dict so next time we don't have to research it
59
60
Assemble.append(Res);
61
Assemble.append(" ");
62
63
64
65
66
67
}
68
69
70
// Delete last space if there is
71
72
73
if (Assemble[Assemble.size() - 1] == ' ')
74
Assemble.pop_back();
75
76
77
return Assemble;
78
}
79
80
EnglishPhoneticProcessor::EnglishPhoneticProcessor()
81
{
82
Phoner = nullptr;
83
}
84
85
EnglishPhoneticProcessor::EnglishPhoneticProcessor(Phonemizer *InPhn)
86
{
87
Initialize(InPhn);
88
89
}
90
91
92
93
EnglishPhoneticProcessor::~EnglishPhoneticProcessor()
94
{
95
if (Phoner)
96
delete Phoner;
97
}
98
99