All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
fsts-to-transcripts.cc File Reference
Include dependency graph for fsts-to-transcripts.cc:

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 

Function Documentation

int main ( int  argc,
char *  argv[] 
)

Definition at line 28 of file fsts-to-transcripts.cc.

References SequentialTableReader< Holder >::Done(), ParseOptions::GetArg(), KALDI_ERR, KALDI_LOG, KALDI_WARN, SequentialTableReader< Holder >::Key(), SequentialTableReader< Holder >::Next(), ParseOptions::NumArgs(), ParseOptions::PrintUsage(), ParseOptions::Read(), ParseOptions::Register(), SequentialTableReader< Holder >::Value(), and TableWriter< Holder >::Write().

28  {
29  try {
30  using namespace kaldi;
31  using namespace fst;
32  typedef kaldi::int32 int32;
33  typedef kaldi::uint64 uint64;
34 
35  const char *usage =
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"
39  "\n"
40  "Usage:\n"
41  " fsts-to-transcripts [options] <fsts-rspecifier>"
42  " <transcriptions-wspecifier>\n"
43  "e.g.:\n"
44  " fsts-to-transcripts ark:train.fsts ark,t:train.text\n";
45 
46  ParseOptions po(usage);
47 
48  bool output_side = true;
49 
50  po.Register("output-side", &output_side, "If true, extract the symbols on "
51  "the output side of the FSTs, else the input side.");
52 
53  po.Read(argc, argv);
54 
55  if (po.NumArgs() != 2) {
56  po.PrintUsage();
57  exit(1);
58  }
59 
60  std::string fst_rspecifier = po.GetArg(1),
61  transcript_wspecifier = po.GetArg(2);
62 
63 
64  SequentialTableReader<VectorFstHolder> fst_reader(fst_rspecifier);
65  Int32VectorWriter transcript_writer(transcript_wspecifier);
66 
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();
71 
72 
73  VectorFst<StdArc> shortest_path;
74  ShortestPath(fst, &shortest_path); // the OpenFst algorithm ShortestPath.
75 
76  if (shortest_path.NumStates() == 0) {
77  KALDI_WARN << "Input FST (after shortest path) was empty. Producing "
78  << "no output for key " << key;
79  n_err++;
80  continue;
81  }
82 
83  std::vector<int32> transcript;
84  bool ans;
85  if (output_side) ans = fst::GetLinearSymbolSequence<StdArc, int32>(
86  shortest_path, NULL, &transcript, NULL);
87  else
88  ans = fst::GetLinearSymbolSequence<StdArc, int32>(
89  shortest_path, &transcript, NULL, NULL);
90  if (!ans) {
91  KALDI_ERR << "GetLinearSymbolSequence returned false (code error);";
92  }
93  transcript_writer.Write(key, transcript);
94  n_done++;
95  }
96 
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();
101  return -1;
102  }
103 }
Relabels neural network egs with the read pdf-id alignments.
Definition: chain.dox:20
Definition: graph.dox:21
A templated class for writing objects to an archive or script file; see The Table concept...
Definition: kaldi-table.h:366
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
Definition: parse-options.h:36
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
Definition: kaldi-table.h:287
#define KALDI_ERR
Definition: kaldi-error.h:127
#define KALDI_WARN
Definition: kaldi-error.h:130
#define KALDI_LOG
Definition: kaldi-error.h:133