34 using namespace kaldi;
39 "Constructs a context FST with a specified context-width and context-position.\n" 40 "Outputs the context FST, and a file in Kaldi format that describes what the\n" 41 "input labels mean. Note: this is very inefficient if there are a lot of phones,\n" 42 "better to use fstcomposecontext instead\n" 44 "Usage: fstmakecontextfst <phones-symbol-table> <subsequential-symbol> <ilabels-output-file> [<out-fst>]\n" 45 "E.g.: fstmakecontextfst phones.txt 42 ilabels.sym > C.fst\n";
48 std::string disambig_rxfilename, disambig_wxfilename;
49 int32 context_width = 3, central_position = 1;
52 po.Register(
"read-disambig-syms", &disambig_rxfilename,
53 "List of disambiguation symbols to read");
54 po.Register(
"write-disambig-syms", &disambig_wxfilename,
55 "List of disambiguation symbols to write");
56 po.Register(
"context-size", &context_width,
"Size of phonetic context window");
57 po.Register(
"central-position", ¢ral_position,
58 "Designated central position in context window");
59 po.Register(
"binary", &binary,
60 "Write ilabels output file in binary Kaldi format");
64 if (po.NumArgs() < 3 || po.NumArgs() > 4) {
69 std::string phones_symtab_filename = po.GetArg(1);
72 KALDI_ERR <<
"Invalid subsequential symbol " << po.GetArg(2);
73 std::string ilabels_out_filename = po.GetArg(3);
74 std::string fst_out_filename = po.GetOptArg(4);
77 std::vector<kaldi::int32> phone_syms;
79 fst::SymbolTable *phones_symtab = NULL;
81 std::ifstream is(phones_symtab_filename.c_str());
82 phones_symtab = fst::SymbolTable::ReadText(is, phones_symtab_filename);
83 if (!phones_symtab)
KALDI_ERR <<
"Could not read phones symbol-table file "<<phones_symtab_filename;
91 if ( (disambig_wxfilename !=
"") && (disambig_rxfilename ==
"") )
92 KALDI_ERR <<
"fstmakecontextfst: cannot specify --write-disambig-syms if " 93 "not specifying --read-disambig-syms\n";
95 std::vector<int32> disambig_in;
96 if (disambig_rxfilename !=
"") {
98 KALDI_ERR <<
"fstcomposecontext: Could not read disambiguation symbols from " 102 if (std::binary_search(phone_syms.begin(), phone_syms.end(), subseq_sym)
103 || std::binary_search(disambig_in.begin(), disambig_in.end(), subseq_sym))
104 KALDI_ERR <<
"Invalid subsequential symbol " << subseq_sym
105 <<
", already a phone or disambiguation symbol.";
111 loop_fst.SetStart(0);
112 loop_fst.SetFinal(0, TropicalWeight::One());
113 for (
size_t i = 0;
i < phone_syms.size();
i++) {
114 int32 sym = phone_syms[
i];
115 loop_fst.AddArc(0,
StdArc(sym, sym, TropicalWeight::One(), 0));
118 std::vector<std::vector<int32> > ilabels;
119 VectorFst<StdArc> context_fst;
122 &loop_fst, &context_fst, &ilabels,
true);
129 if (disambig_wxfilename !=
"") {
130 std::vector<int32> disambig_out;
131 for (
size_t i = 0;
i < ilabels.size();
i++)
132 if (ilabels[
i].size() == 1 && ilabels[
i][0] <= 0)
133 disambig_out.push_back(static_cast<int32>(
i));
135 KALDI_ERR <<
"fstcomposecontext: Could not write disambiguation symbols to " 139 }
catch(
const std::exception &e) {
140 std::cerr << e.what();
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
void WriteILabelInfo(std::ostream &os, bool binary, const vector< vector< int32 > > &info)
Utility function for writing ilabel-info vectors to disk.
bool ConvertStringToInteger(const std::string &str, Int *out)
Converts a string into an integer via strtoll and returns false if there was any kind of problem (i...
void GetSymbols(const SymbolTable &symtab, bool include_eps, std::vector< I > *syms_out)
For an extended explanation of the framework of which grammar-fsts are a part, please see Support for...
fst::StdVectorFst StdVectorFst
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
void ComposeContext(const vector< int32 > &disambig_syms_in, int32 context_width, int32 central_position, VectorFst< StdArc > *ifst, VectorFst< StdArc > *ofst, vector< vector< int32 > > *ilabels_out, bool project_ifst)
Used in the command-line tool fstcomposecontext.
void WriteFstKaldi(std::ostream &os, bool binary, const VectorFst< Arc > &t)
bool WriteIntegerVectorSimple(const std::string &wxfilename, const std::vector< int32 > &list)
WriteToList attempts to write this list of integers, one per line, to the given file, in text format.
std::string PrintableRxfilename(const std::string &rxfilename)
PrintableRxfilename turns the rxfilename into a more human-readable form for error reporting...
std::string PrintableWxfilename(const std::string &wxfilename)
PrintableWxfilename turns the wxfilename into a more human-readable form for error reporting...
bool ReadIntegerVectorSimple(const std::string &rxfilename, std::vector< int32 > *list)
ReadFromList attempts to read this list of integers, one per line, from the given file...