lattice-depth-per-frame.cc File Reference
Include dependency graph for lattice-depth-per-frame.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 28 of file lattice-depth-per-frame.cc.

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

28  {
29  try {
30  using namespace kaldi;
31  typedef kaldi::int32 int32;
32  typedef kaldi::int64 int64;
33 
34  using fst::VectorFst;
35  using fst::StdArc;
36  typedef StdArc::StateId StateId;
37 
38  const char *usage =
39  "For each lattice, compute a vector of length (num-frames) saying how\n"
40  "may arcs cross each frame. See also lattice-depth\n"
41  "Usage: lattice-depth-per-frame <lattice-rspecifier> <depth-wspecifier> [<lattice-wspecifier>]\n"
42  "The final <lattice-wspecifier> allows you to write the input lattices out\n"
43  "in case you want to do something else with them as part of the same pipe.\n"
44  "E.g.: lattice-depth-per-frame ark:- ark,t:-\n";
45 
46  ParseOptions po(usage);
47 
48  po.Read(argc, argv);
49 
50  if (po.NumArgs() < 2 || po.NumArgs() > 3) {
51  po.PrintUsage();
52  exit(1);
53  }
54 
55  std::string lats_rspecifier = po.GetArg(1);
56  SequentialCompactLatticeReader clat_reader(lats_rspecifier);
57 
58  std::string depth_wspecifier = po.GetArg(2);
59  Int32VectorWriter lats_depth_writer(depth_wspecifier);
60 
61  std::string lattice_wspecifier = po.GetOptArg(3);
62  CompactLatticeWriter clat_writer(lattice_wspecifier);
63 
64  int64 num_done = 0;
65 
66  for (; !clat_reader.Done(); clat_reader.Next()) {
67  CompactLattice clat = clat_reader.Value();
68  std::string key = clat_reader.Key();
69 
71 
72  std::vector<int32> depth_per_frame;
73  CompactLatticeDepthPerFrame(clat, &depth_per_frame);
74 
75  lats_depth_writer.Write(key, depth_per_frame);
76 
77  if (!lattice_wspecifier.empty())
78  clat_writer.Write(key, clat);
79 
80  num_done++;
81  }
82  KALDI_LOG << "Done " << num_done << " lattices.";
83  if (num_done != 0) return 0;
84  else return 1;
85  } catch (const std::exception &e) {
86  std::cerr << e.what();
87  return -1;
88  }
89 }
fst::StdArc::StateId StateId
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
Lattice::StateId StateId
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< CompactLatticeArc > CompactLattice
Definition: kaldi-lattice.h:46
void TopSortCompactLatticeIfNeeded(CompactLattice *clat)
Topologically sort the compact lattice if not already topologically sorted.
void CompactLatticeDepthPerFrame(const CompactLattice &clat, std::vector< int32 > *depth_per_frame)
This function returns, for each frame, the number of arcs crossing that frame.
#define KALDI_LOG
Definition: kaldi-error.h:153