23 #include "fst/fstlib.h" 66 int main(
int argc,
char *argv[]) {
68 using namespace kaldi;
90 "Composes on the left with a dynamically created context FST\n" 92 "Usage: fstcomposecontext <ilabels-output-file> [<in.fst> [<out.fst>] ]\n" 93 "E.g: fstcomposecontext ilabels.sym < LG.fst > CLG.fst\n";
98 std::string disambig_rxfilename,
100 int32 context_width = 3, central_position = 1;
101 int32 nonterm_phones_offset = -1;
103 "If true, output ilabels-output-file in binary format");
104 po.
Register(
"read-disambig-syms", &disambig_rxfilename,
105 "List of disambiguation symbols on input of in.fst");
106 po.
Register(
"write-disambig-syms", &disambig_wxfilename,
107 "List of disambiguation symbols on input of out.fst");
108 po.
Register(
"context-size", &context_width,
"Size of phone context window");
109 po.
Register(
"central-position", ¢ral_position,
110 "Designated central position in context window");
111 po.
Register(
"nonterm-phones-offset", &nonterm_phones_offset,
112 "The integer id of #nonterm_bos in your phones.txt, if present " 113 "(only relevant for grammar-FST construction, see " 123 std::string ilabels_out_filename = po.
GetArg(1),
129 if ( (disambig_wxfilename !=
"") && (disambig_rxfilename ==
"") )
130 KALDI_ERR <<
"fstcomposecontext: cannot specify --write-disambig-syms if " 131 "not specifying --read-disambig-syms\n";
133 std::vector<int32> disambig_in;
134 if (disambig_rxfilename !=
"")
136 KALDI_ERR <<
"fstcomposecontext: Could not read disambiguation symbols from " 139 if (disambig_in.empty()) {
140 KALDI_WARN <<
"Disambiguation symbols list is empty; this likely " 141 <<
"indicates an error in data preparation.";
144 std::vector<std::vector<int32> > ilabels;
145 VectorFst<StdArc> composed_fst;
148 if (nonterm_phones_offset < 0) {
151 fst, &composed_fst, &ilabels);
154 if (context_width != 2 || central_position != 1) {
155 KALDI_ERR <<
"Grammar-fst graph creation only supports models with left-" 156 "biphone context. (--nonterm-phones-offset option was supplied).";
159 *fst, &composed_fst, &ilabels);
164 if (disambig_wxfilename !=
"") {
165 std::vector<int32> disambig_out;
166 for (
size_t i = 0;
i < ilabels.size();
i++)
167 if (ilabels[
i].size() == 1 && ilabels[
i][0] <= 0)
168 disambig_out.push_back(static_cast<int32>(
i));
170 std::cerr <<
"fstcomposecontext: Could not write disambiguation symbols to " 179 }
catch(
const std::exception &e) {
180 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.
int main(int argc, char *argv[])
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 Register(const std::string &name, bool *ptr, const std::string &doc)
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
int Read(int argc, const char *const *argv)
Parses the command line options and fills the ParseOptions-registered variables.
void ComposeContextLeftBiphone(int32 nonterm_phones_offset, const vector< int32 > &disambig_syms_in, const VectorFst< StdArc > &ifst, VectorFst< StdArc > *ofst, std::vector< std::vector< int32 > > *ilabels)
This is a variant of the function ComposeContext() which is to be used with our "grammar FST" framewo...
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).
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)
void ReadFstKaldi(std::istream &is, bool binary, VectorFst< Arc > *fst)
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...
std::string GetOptArg(int param) const