gmm-copy.cc File Reference
Include dependency graph for gmm-copy.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 25 of file gmm-copy.cc.

References ParseOptions::GetArg(), KALDI_LOG, ParseOptions::NumArgs(), ParseOptions::PrintUsage(), AmDiagGmm::Read(), ParseOptions::Read(), TransitionModel::Read(), ParseOptions::Register(), Output::Stream(), Input::Stream(), AmDiagGmm::Write(), and TransitionModel::Write().

25  {
26  try {
27  using namespace kaldi;
28  typedef kaldi::int32 int32;
29 
30  const char *usage =
31  "Copy GMM based model (and possibly change binary/text format)\n"
32  "Usage: gmm-copy [options] <model-in> <model-out>\n"
33  "e.g.:\n"
34  " gmm-copy --binary=false 1.mdl 1_txt.mdl\n";
35 
36 
37  bool binary_write = true,
38  copy_am = true,
39  copy_tm = true;
40 
41  ParseOptions po(usage);
42  po.Register("binary", &binary_write, "Write output in binary mode");
43  po.Register("copy-am", &copy_am, "Copy the acoustic model (AmDiagGmm object)");
44  po.Register("copy-tm", &copy_tm, "Copy the transition model");
45 
46  po.Read(argc, argv);
47 
48  if (po.NumArgs() != 2) {
49  po.PrintUsage();
50  exit(1);
51  }
52 
53  std::string model_in_filename = po.GetArg(1),
54  model_out_filename = po.GetArg(2);
55 
56  AmDiagGmm am_gmm;
57  TransitionModel trans_model;
58  {
59  bool binary_read;
60  Input ki(model_in_filename, &binary_read);
61  if (copy_tm)
62  trans_model.Read(ki.Stream(), binary_read);
63  if (copy_am)
64  am_gmm.Read(ki.Stream(), binary_read);
65  }
66 
67  {
68  Output ko(model_out_filename, binary_write);
69  if (copy_tm)
70  trans_model.Write(ko.Stream(), binary_write);
71  if (copy_am)
72  am_gmm.Write(ko.Stream(), binary_write);
73  }
74 
75  KALDI_LOG << "Written model to " << model_out_filename;
76  } catch(const std::exception &e) {
77  std::cerr << e.what() << '\n';
78  return -1;
79  }
80 }
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
kaldi::int32 int32
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
Definition: parse-options.h:36
void Read(std::istream &is, bool binary)
void Write(std::ostream &os, bool binary) const
void Write(std::ostream &out_stream, bool binary) const
Definition: am-diag-gmm.cc:163
#define KALDI_LOG
Definition: kaldi-error.h:153
void Read(std::istream &in_stream, bool binary)
Definition: am-diag-gmm.cc:147