Path: blob/master/examples/cppwin/TensorflowTTSCppInference/phonemizer.h
1559 views
#ifndef PHONEMIZER_H1#define PHONEMIZER_H2#include "tfg2p.h"3#include <tuple>4#include <set>5#include <algorithm>67struct IdStr{8int32_t ID;9std::string STR;10};111213struct StrStr{14std::string Word;15std::string Phn;16};171819class Phonemizer20{21private:22TFG2P G2pModel;2324std::vector<IdStr> CharId;25std::vector<IdStr> PhnId;26272829303132std::vector<IdStr> GetDelimitedFile(const std::string& InFname);333435// Sorry, can't use set, unordered_map or any other types. (I tried)36std::vector<StrStr> Dictionary;3738void LoadDictionary(const std::string& InDictFn);3940std::string DictLookup(const std::string& InWord);41424344std::string PhnLanguage;45public:46Phonemizer();47/*48* Initialize a phonemizer49* Expects:50* - Two files consisting in TOKEN \t ID:51* -- char2id.txt: Translation from input character to ID the model can accept52* -- phn2id.txt: Translation from output ID from the model to phoneme53* - A model/ folder where a G2P-Tensorflow model was saved as SavedModel54* - dict.txt: Phonetic dictionary. First it searches the word there and if it can't be found then it uses the model.5556*/57bool Initialize(const std::string InPath);58std::string ProcessWord(const std::string& InWord, float Temperature = 0.1f);59std::string GetPhnLanguage() const;60void SetPhnLanguage(const std::string &value);6162std::string GetGraphemeChars();6364};656667bool operator<(const StrStr& right,const StrStr& left);68#endif // PHONEMIZER_H697071