Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
TensorSpeech
GitHub Repository: TensorSpeech/TensorFlowTTS
Path: blob/master/examples/cppwin/TensorflowTTSCppInference/phonemizer.h
1559 views
1
#ifndef PHONEMIZER_H
2
#define PHONEMIZER_H
3
#include "tfg2p.h"
4
#include <tuple>
5
#include <set>
6
#include <algorithm>
7
8
struct IdStr{
9
int32_t ID;
10
std::string STR;
11
};
12
13
14
struct StrStr{
15
std::string Word;
16
std::string Phn;
17
};
18
19
20
class Phonemizer
21
{
22
private:
23
TFG2P G2pModel;
24
25
std::vector<IdStr> CharId;
26
std::vector<IdStr> PhnId;
27
28
29
30
31
32
33
std::vector<IdStr> GetDelimitedFile(const std::string& InFname);
34
35
36
// Sorry, can't use set, unordered_map or any other types. (I tried)
37
std::vector<StrStr> Dictionary;
38
39
void LoadDictionary(const std::string& InDictFn);
40
41
std::string DictLookup(const std::string& InWord);
42
43
44
45
std::string PhnLanguage;
46
public:
47
Phonemizer();
48
/*
49
* Initialize a phonemizer
50
* Expects:
51
* - Two files consisting in TOKEN \t ID:
52
* -- char2id.txt: Translation from input character to ID the model can accept
53
* -- phn2id.txt: Translation from output ID from the model to phoneme
54
* - A model/ folder where a G2P-Tensorflow model was saved as SavedModel
55
* - dict.txt: Phonetic dictionary. First it searches the word there and if it can't be found then it uses the model.
56
57
*/
58
bool Initialize(const std::string InPath);
59
std::string ProcessWord(const std::string& InWord, float Temperature = 0.1f);
60
std::string GetPhnLanguage() const;
61
void SetPhnLanguage(const std::string &value);
62
63
std::string GetGraphemeChars();
64
65
};
66
67
68
bool operator<(const StrStr& right,const StrStr& left);
69
#endif // PHONEMIZER_H
70
71