Download cpp/tools/g2p_dump.cpp from RL10x/tiny-voca-hindi: direct link, hf CLI and curl.
- Browser
- Download file 1.79 kB
-
https://huggingface.co/RL10x/tiny-voca-hindi/resolve/main/cpp/tools/g2p_dump.cpp
- Command line
-
hf download hf://RL10x/tiny-voca-hindi/cpp/tools/g2p_dump.cpp
-
curl -L -o g2p_dump.cpp https://huggingface.co/RL10x/tiny-voca-hindi/resolve/main/cpp/tools/g2p_dump.cpp
1.79 kB
| // Run the C++ front end over a text file (one input per line) and write, per line, tab-separated: | |
| // phoneme ids (space separated) or "NOTHING" | nasal flags | sentences(finished(text)) joined by U+001F | | |
| // shorter(text) joined by U+001F | |
| // scripts/tts_hi_g2p_compare.py runs the Python front end on the same lines and reports every difference. | |
| // tts_g2p_dump model.gguf texts.txt out.tsv | |
| static std::string join(const std::vector<std::string>& v, const std::string& sep) { | |
| std::string s; | |
| for (size_t i = 0; i < v.size(); ++i) { if (i) s += sep; s += v[i]; } | |
| return s; | |
| } | |
| int main(int argc, char** argv) { | |
| if (argc < 4) { std::cerr << "usage: tts_g2p_dump model.gguf texts.txt out.tsv\n"; return 2; } | |
| auto model = TtsModel::load(argv[1], 1); | |
| HindiG2P g2p(model->symbols()); | |
| std::ifstream in(argv[2], std::ios::binary); | |
| std::ofstream out(argv[3], std::ios::binary); | |
| std::string line; | |
| const std::string US = "\x1f"; | |
| size_t n = 0; | |
| while (std::getline(in, line)) { | |
| if (!line.empty() && line.back() == '\r') line.pop_back(); | |
| std::string ids, stress; | |
| try { | |
| const Phonemized p = g2p.phonemize(line); | |
| for (size_t i = 0; i < p.ids.size(); ++i) { | |
| if (i) { ids += ' '; stress += ' '; } | |
| ids += std::to_string(p.ids[i]); stress += std::to_string(p.stress[i]); | |
| } | |
| } catch (const NothingToPronounce&) { | |
| ids = "NOTHING"; | |
| } | |
| out << ids << '\t' << stress << '\t' << join(split_sentences(finished(line)), US) << '\t' | |
| << join(shorter(line), US) << '\n'; | |
| ++n; | |
| } | |
| std::cerr << n << " lines\n"; | |
| return 0; | |
| } | |