lattice-reverse.cc File Reference
Include dependency graph for lattice-reverse.cc:

Go to the source code of this file.

Functions

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

Function Documentation

◆ main()

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

Definition at line 26 of file lattice-reverse.cc.

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

26  {
27  try {
28  using namespace kaldi;
29  typedef kaldi::int32 int32;
30  typedef kaldi::int64 int64;
31  using fst::SymbolTable;
32  using fst::VectorFst;
33  using fst::StdArc;
34 
35  using std::string;
36 
37  const char *usage =
38  "Reverse a lattice in order to rescore the lattice with a RNNLM \n"
39  "trained reversed text. An example for its application is at \n"
40  "swbd/local/rnnlm/run_lstm_tdnn_back.sh\n"
41  "Usage: lattice-reverse lattice-rspecifier lattice-wspecifier\n"
42  " e.g.: lattice-reverse ark:forward.lats ark:backward.lats\n";
43 
44  ParseOptions po(usage);
45  std::string include_rxfilename;
46  std::string exclude_rxfilename;
47 
48  po.Read(argc, argv);
49 
50  if (po.NumArgs() != 2) {
51  po.PrintUsage();
52  exit(1);
53  }
54 
55  std::string lats_rspecifier = po.GetArg(1),
56  lats_wspecifier = po.GetArg(2);
57 
58  int32 n_done = 0;
59 
60  SequentialLatticeReader lattice_reader(lats_rspecifier);
61  LatticeWriter lattice_writer(lats_wspecifier);
62 
63  for (; !lattice_reader.Done(); lattice_reader.Next(), n_done++) {
64  string key = lattice_reader.Key();
65  Lattice &lat = lattice_reader.Value();
66  Lattice olat;
67  fst::Reverse(lat, &olat);
68  lattice_writer.Write(lattice_reader.Key(), olat);
69  }
70 
71  KALDI_LOG << "Done reversing " << n_done << " lattices.";
72 
73  return (n_done != 0 ? 0 : 1);
74  } catch(const std::exception &e) {
75  std::cerr << e.what();
76  return -1;
77  }
78 }
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
fst::StdArc StdArc
A templated class for writing objects to an archive or script file; see The Table concept...
Definition: kaldi-table.h:368
kaldi::int32 int32
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
fst::VectorFst< LatticeArc > Lattice
Definition: kaldi-lattice.h:44
#define KALDI_LOG
Definition: kaldi-error.h:153