make-h-transducer.cc File Reference
#include "hmm/transition-model.h"
#include "hmm/hmm-utils.h"
#include "tree/context-dep.h"
#include "util/common-utils.h"
#include "fst/fstlib.h"
#include "fstext/table-matcher.h"
#include "fstext/fstext-utils.h"
#include "fstext/context-fst.h"
Include dependency graph for make-h-transducer.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 29 of file make-h-transducer.cc.

References ParseOptions::GetArg(), kaldi::GetHTransducer(), KALDI_ERR, ParseOptions::NumArgs(), ParseOptions::PrintUsage(), ParseOptions::Read(), fst::ReadILabelInfo(), kaldi::ReadKaldiObject(), HTransducerConfig::Register(), ParseOptions::Register(), Input::Stream(), and kaldi::WriteIntegerVectorSimple().

29  {
30  try {
31  using namespace kaldi;
32  typedef kaldi::int32 int32;
33  using fst::SymbolTable;
34  using fst::VectorFst;
35  using fst::StdArc;
36 
37  const char *usage =
38  "Make H transducer from transition-ids to context-dependent phones, \n"
39  " without self-loops [use add-self-loops to add them]\n"
40  "Usage: make-h-transducer <ilabel-info-file> <tree-file> <transition-gmm/acoustic-model> [<H-fst-out>]\n"
41  "e.g.: \n"
42  " make-h-transducer ilabel_info 1.tree 1.mdl > H.fst\n";
43  ParseOptions po(usage);
44 
45  HTransducerConfig hcfg;
46  std::string disambig_out_filename;
47  hcfg.Register(&po);
48  po.Register("disambig-syms-out", &disambig_out_filename, "List of disambiguation symbols on input of H [to be output from this program]");
49 
50  po.Read(argc, argv);
51 
52  if (po.NumArgs() < 3 || po.NumArgs() > 4) {
53  po.PrintUsage();
54  exit(1);
55  }
56 
57  std::string ilabel_info_filename = po.GetArg(1);
58  std::string tree_filename = po.GetArg(2);
59  std::string model_filename = po.GetArg(3);
60  std::string fst_out_filename;
61  if (po.NumArgs() >= 4) fst_out_filename = po.GetArg(4);
62  if (fst_out_filename == "-") fst_out_filename = "";
63 
64  std::vector<std::vector<int32> > ilabel_info;
65  {
66  bool binary_in;
67  Input ki(ilabel_info_filename, &binary_in);
68  fst::ReadILabelInfo(ki.Stream(), binary_in, &ilabel_info);
69  }
70 
71  ContextDependency ctx_dep;
72  ReadKaldiObject(tree_filename, &ctx_dep);
73 
74  TransitionModel trans_model;
75  ReadKaldiObject(model_filename, &trans_model);
76 
77  std::vector<int32> disambig_syms_out;
78 
79  // The work gets done here.
80  fst::VectorFst<fst::StdArc> *H = GetHTransducer (ilabel_info,
81  ctx_dep,
82  trans_model,
83  hcfg,
84  &disambig_syms_out);
85 #if _MSC_VER
86  if (fst_out_filename == "")
87  _setmode(_fileno(stdout), _O_BINARY);
88 #endif
89 
90  if (disambig_out_filename != "") { // if option specified..
91  if (disambig_out_filename == "-")
92  disambig_out_filename = "";
93  if (! WriteIntegerVectorSimple(disambig_out_filename, disambig_syms_out))
94  KALDI_ERR << "Could not write disambiguation symbols to "
95  << (disambig_out_filename == "" ?
96  "standard output" : disambig_out_filename);
97  }
98 
99  if (! H->Write(fst_out_filename) )
100  KALDI_ERR << "make-h-transducer: error writing FST to "
101  << (fst_out_filename == "" ?
102  "standard output" : fst_out_filename);
103 
104  delete H;
105  return 0;
106  } catch(const std::exception &e) {
107  std::cerr << e.what();
108  return -1;
109  }
110 }
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
void Register(OptionsItf *opts)
Definition: hmm-utils.h:47
fst::StdArc StdArc
kaldi::int32 int32
void ReadKaldiObject(const std::string &filename, Matrix< float > *m)
Definition: kaldi-io.cc:832
void ReadILabelInfo(std::istream &is, bool binary, vector< vector< int32 > > *info)
Utility function for reading ilabel-info vectors from disk.
Definition: context-fst.cc:335
Configuration class for the GetHTransducer() function; see The HTransducerConfig configuration class ...
Definition: hmm-utils.h:36
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
Definition: parse-options.h:36
#define KALDI_ERR
Definition: kaldi-error.h:147
fst::VectorFst< fst::StdArc > * GetHTransducer(const std::vector< std::vector< int32 > > &ilabel_info, const ContextDependencyInterface &ctx_dep, const TransitionModel &trans_model, const HTransducerConfig &config, std::vector< int32 > *disambig_syms_left)
Returns the H tranducer; result owned by caller.
Definition: hmm-utils.cc:254
bool WriteIntegerVectorSimple(const std::string &wxfilename, const std::vector< int32 > &list)
WriteToList attempts to write this list of integers, one per line, to the given file, in text format.