25 #include "fst/fstlib.h" 32 int main(
int argc,
char *argv[]) {
34 using namespace kaldi;
36 using fst::SymbolTable;
41 "Add self-loops and transition probabilities to transducer. Input transducer\n" 42 "has transition-ids on the input side, but only the forward transitions, not the\n" 43 "self-loops. Output transducer has transition-ids on the input side, but with\n" 44 "self-loops added. The --reorder option controls whether the loop is added before\n" 45 "the forward transition (if false), or afterward (if true). The default (true)\n" 46 "is recommended as the decoding will in that case be faster.\n" 47 "Usage: add-self-loops [options] transition-gmm/acoustic-model [fst-in] [fst-out]\n" 49 " add-self-loops --self-loop-scale=0.1 1.mdl HCLGa.fst HCLG.fst\n" 50 "or: add-self-loops --self-loop-scale=0.1 1.mdl <HCLGa.fst >HCLG.fst\n";
54 std::string disambig_in_filename;
57 po.
Register(
"self-loop-scale", &self_loop_scale,
58 "Scale for self-loop probabilities relative to LM.");
59 po.
Register(
"disambig-syms", &disambig_in_filename,
60 "List of disambiguation symbols on input of fst-in [input file]");
62 "If true, reorder symbols for more decoding efficiency");
70 std::string model_in_filename = po.
GetArg(1);
71 std::string fst_in_filename = po.
GetOptArg(2);
72 if (fst_in_filename ==
"-") fst_in_filename =
"";
73 std::string fst_out_filename = po.
GetOptArg(3);
74 if (fst_out_filename ==
"-") fst_out_filename =
"";
76 if (fst_in_filename ==
"")
77 _setmode(_fileno(stdin), _O_BINARY);
78 if (fst_out_filename ==
"")
79 _setmode(_fileno(stdout), _O_BINARY);
82 std::vector<int32> disambig_syms_in;
83 if (disambig_in_filename !=
"") {
84 if (disambig_in_filename ==
"-") disambig_in_filename =
"";
86 KALDI_ERR <<
"add-self-loops: could not read disambig symbols from " 87 <<(disambig_in_filename ==
"" ?
88 "standard input" : disambig_in_filename);
95 fst::VectorFst<fst::StdArc> *
fst =
96 fst::VectorFst<fst::StdArc>::Read(fst_in_filename);
98 KALDI_ERR <<
"add-self-loops: error reading input FST.";
100 bool check_no_self_loops =
true;
106 reorder, check_no_self_loops, fst);
108 if (! fst->Write(fst_out_filename) )
109 KALDI_ERR <<
"add-self-loops: error writing FST to " 110 << (fst_out_filename ==
"" ?
111 "standard output" : fst_out_filename);
115 }
catch(
const std::exception &e) {
116 std::cerr << e.what();
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
For an extended explanation of the framework of which grammar-fsts are a part, please see Support for...
void PrintUsage(bool print_command_line=false)
Prints the usage documentation [provided in the constructor].
void AddSelfLoops(const TransitionModel &trans_model, const std::vector< int32 > &disambig_syms, BaseFloat self_loop_scale, bool reorder, bool check_no_self_loops, fst::VectorFst< fst::StdArc > *fst)
For context, see AddSelfLoops().
void Register(const std::string &name, bool *ptr, const std::string &doc)
void ReadKaldiObject(const std::string &filename, Matrix< float > *m)
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
int main(int argc, char *argv[])
Add self-loops and transition probabilities to transducer, expanding to transition-ids.
int Read(int argc, const char *const *argv)
Parses the command line options and fills the ParseOptions-registered variables.
std::string GetArg(int param) const
Returns one of the positional parameters; 1-based indexing for argc/argv compatibility.
int NumArgs() const
Number of positional parameters (c.f. argc-1).
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...
std::string GetOptArg(int param) const