Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
TensorSpeech
GitHub Repository: TensorSpeech/TensorFlowTTS
Path: blob/master/examples/cpptflite/src/TTSFrontend.cpp
1559 views
1
#include "TTSFrontend.h"
2
3
void TTSFrontend::text2ids(const std::string &text)
4
{
5
_phonesIds = strSplit(getCmdResult(text));
6
}
7
8
std::string TTSFrontend::getCmdResult(const std::string &text)
9
{
10
char buf[1000] = {0};
11
FILE *pf = NULL;
12
13
if( (pf = popen((_strCmd + " " + _mapperJson + " \"" + text + "\"").c_str(), "r")) == NULL )
14
{
15
return "";
16
}
17
18
while(fgets(buf, sizeof(buf), pf))
19
{
20
continue;
21
}
22
23
std::string strResult(buf);
24
pclose(pf);
25
26
return strResult;
27
}
28
29
std::vector<int32_t> TTSFrontend::strSplit(const std::string &idStr)
30
{
31
std::vector<int32_t> idsVector;
32
33
std::regex rgx ("\\s+");
34
std::sregex_token_iterator iter(idStr.begin(), idStr.end(), rgx, -1);
35
std::sregex_token_iterator end;
36
37
while (iter != end) {
38
idsVector.push_back(stoi(*iter));
39
++iter;
40
}
41
42
return idsVector;
43
}
44