File size: 1,470 Bytes
ab1b068 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | // Hindi front end in C++: Devanagari text -> phoneme symbols + nasal flags. Port of tts_hi/tiny_voca/text.py
// (normalize_text, _aksharas, _word_phones, chunks, tokenize, phonemize) and the sentence helpers of
// tts_hi/tiny_voca/infer.py (sentences, finished, shorter). Checked against Python by tools/g2p_check.cpp.
#pragma once
#include <cstdint>
#include <stdexcept>
#include <string>
#include <vector>
struct Phonemized {
std::vector<std::string> symbols; // IPA phones, punctuation, <bos> <eos> <sp> <unk>
std::vector<int32_t> ids; // indices into the model's symbol table
std::vector<int32_t> stress; // 1 = nasalized vowel
};
class NothingToPronounce : public std::runtime_error {
public:
using std::runtime_error::runtime_error;
};
// symbols: the model's symbol table (GGUF tinyvoca.symbols), in id order.
class HindiG2P {
public:
explicit HindiG2P(const std::vector<std::string>& symbols);
Phonemized phonemize(const std::string& text) const; // throws NothingToPronounce
private:
std::vector<std::string> symbols_;
int id_of(const std::string& s) const;
};
std::string normalize_text(const std::string& text); // text.normalize_text
std::vector<std::string> split_sentences(const std::string& text); // infer.sentences
std::string finished(const std::string& text); // infer.finished
std::vector<std::string> shorter(const std::string& text); // infer.shorter
|