28 int main(
int argc,
char *argv[]) {
30 using namespace kaldi;
33 typedef kaldi::uint64 uint64;
36 "Reads a table of FSTs; for each element, finds the best path and \n" 37 "prints out the output-symbol sequence (if --output-side=true), or \n" 38 "input-symbol sequence otherwise.\n" 41 " fsts-to-transcripts [options] <fsts-rspecifier>" 42 " <transcriptions-wspecifier>\n" 44 " fsts-to-transcripts ark:train.fsts ark,t:train.text\n";
48 bool output_side =
true;
50 po.
Register(
"output-side", &output_side,
"If true, extract the symbols on " 51 "the output side of the FSTs, else the input side.");
60 std::string fst_rspecifier = po.
GetArg(1),
61 transcript_wspecifier = po.
GetArg(2);
67 int32 n_done = 0, n_err = 0;
68 for (; !fst_reader.
Done(); fst_reader.
Next()) {
69 std::string key = fst_reader.
Key();
70 const VectorFst<StdArc> &
fst = fst_reader.
Value();
73 VectorFst<StdArc> shortest_path;
74 ShortestPath(fst, &shortest_path);
76 if (shortest_path.NumStates() == 0) {
77 KALDI_WARN <<
"Input FST (after shortest path) was empty. Producing " 78 <<
"no output for key " << key;
83 std::vector<int32> transcript;
85 if (output_side) ans = fst::GetLinearSymbolSequence<StdArc, int32>(
86 shortest_path, NULL, &transcript, NULL);
88 ans = fst::GetLinearSymbolSequence<StdArc, int32>(
89 shortest_path, &transcript, NULL, NULL);
91 KALDI_ERR <<
"GetLinearSymbolSequence returned false (code error);";
93 transcript_writer.
Write(key, transcript);
97 KALDI_LOG <<
"Converted " << n_done <<
" FSTs, " << n_err <<
" with errors";
98 return (n_done != 0 ? 0 : 1);
99 }
catch(
const std::exception &e) {
100 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].
int main(int argc, char *argv[])
A templated class for writing objects to an archive or script file; see The Table concept...
void Write(const std::string &key, const T &value) const
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...
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
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).