lattice-to-phone-lattice.cc File Reference
Include dependency graph for lattice-to-phone-lattice.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-to-phone-lattice.cc.

References kaldi::ConvertCompactLatticeToPhones(), fst::ConvertLattice(), kaldi::ConvertLatticeToPhones(), SequentialTableReader< Holder >::Done(), ParseOptions::GetArg(), KALDI_LOG, SequentialTableReader< Holder >::Key(), SequentialTableReader< Holder >::Next(), ParseOptions::NumArgs(), ParseOptions::PrintUsage(), ParseOptions::Read(), kaldi::ReadKaldiObject(), ParseOptions::Register(), 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  using fst::SymbolTable;
34  using fst::VectorFst;
35  using fst::StdArc;
36 
37  const char *usage =
38  "Convert the words or transition-ids into phones, which are worked out\n"
39  "from the transition-ids. If --replace-words=true (true by default),\n"
40  "replaces the words with phones, otherwise replaces the transition-ids.\n"
41  "If --replace-words=false, it will preserve the alignment of transition-ids/phones\n"
42  "to words, so that if you do \n"
43  "lattice-align-words | lattice-to-phone-lattice --replace-words=false,\n"
44  "you can get the phones corresponding to each word in the lattice.\n"
45  "\n"
46  "Usage: lattice-to-phone-lattice [options] model lattice-rspecifier lattice-wspecifier\n"
47  " e.g.: lattice-to-phone-lattice 1.mdl ark:1.lats ark:phones.lats\n"
48  "See also: lattice-align-words, lattice-align-phones\n";
49 
50  ParseOptions po(usage);
51  bool replace_words = true;
52  po.Register("replace-words", &replace_words,
53  "If true, replace words with phones; otherwise replace "
54  "transition-ids with phones.");
55 
56  po.Read(argc, argv);
57 
58  if (po.NumArgs() != 3) {
59  po.PrintUsage();
60  exit(1);
61  }
62 
63  std::string model_rxfilename = po.GetArg(1),
64  lats_rspecifier = po.GetArg(2),
65  lats_wspecifier = po.GetArg(3);
66 
67  int32 n_done = 0;
68 
69  TransitionModel trans_model;
70 
71  ReadKaldiObject(model_rxfilename, &trans_model);
72 
73  SequentialCompactLatticeReader clat_reader(lats_rspecifier);
74  CompactLatticeWriter clat_writer(lats_wspecifier); // write as compact.
75  for (; !clat_reader.Done(); clat_reader.Next()) {
76  if (replace_words) {
77  Lattice lat;
78  ConvertLattice(clat_reader.Value(), &lat);
79  ConvertLatticeToPhones(trans_model, &lat); // this function replaces words -> phones
80  CompactLattice clat;
81  ConvertLattice(lat, &clat);
82  clat_writer.Write(clat_reader.Key(), clat);
83  } else { // replace transition-ids with phones.
84  CompactLattice clat(clat_reader.Value());
85  ConvertCompactLatticeToPhones(trans_model, &clat);
86  // this function replaces transition-ids with phones. We do it in the
87  // CompactLattice form, in order to preserve the alignment of
88  // transition-id sequences/phones-sequences to words [e.g. if you just
89  // did lattice-align-words].
90  clat_writer.Write(clat_reader.Key(), clat);
91  }
92  n_done++;
93  }
94  KALDI_LOG << "Done converting " << n_done << " lattices.";
95  return (n_done != 0 ? 0 : 1);
96  } catch(const std::exception &e) {
97  std::cerr << e.what();
98  return -1;
99  }
100 }
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
void ConvertCompactLatticeToPhones(const TransitionModel &trans, CompactLattice *clat)
Given a lattice, and a transition model to map pdf-ids to phones, replace the sequences of transition...
void ReadKaldiObject(const std::string &filename, Matrix< float > *m)
Definition: kaldi-io.cc:832
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
Definition: parse-options.h:36
void ConvertLattice(const ExpandedFst< ArcTpl< Weight > > &ifst, MutableFst< ArcTpl< CompactLatticeWeightTpl< Weight, Int > > > *ofst, bool invert)
Convert lattice from a normal FST to a CompactLattice FST.
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
fst::VectorFst< CompactLatticeArc > CompactLattice
Definition: kaldi-lattice.h:46
void ConvertLatticeToPhones(const TransitionModel &trans, Lattice *lat)
Given a lattice, and a transition model to map pdf-ids to phones, replace the output symbols (presuma...
#define KALDI_LOG
Definition: kaldi-error.h:153