copy-transition-model.cc
Go to the documentation of this file.
1 // bin/copy-transition-model.cc
2 
3 // Copyright 2009-2011 Microsoft Corporation
4 
5 // See ../../COPYING for clarification regarding multiple authors
6 //
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 //
11 // http://www.apache.org/licenses/LICENSE-2.0
12 //
13 // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
15 // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
16 // MERCHANTABLITY OR NON-INFRINGEMENT.
17 // See the Apache 2 License for the specific language governing permissions and
18 // limitations under the License.
19 
20 #include "hmm/transition-model.h"
21 #include "fst/fstlib.h"
22 #include "util/common-utils.h"
23 
24 
25 int main(int argc, char *argv[]) {
26  try {
27  using namespace kaldi;
28  typedef kaldi::int32 int32;
29  using fst::SymbolTable;
30  using fst::VectorFst;
31  using fst::StdArc;
32 
33  const char *usage =
34  "Copies a transition model (this can be used to separate transition \n"
35  " models from the acoustic models they are written with.\n"
36  "Usage: copy-transition-model [options] <transition-model or model file> <transition-model-out>\n"
37  "e.g.: \n"
38  " copy-transition-model --binary=false 1.mdl 1.txt\n";
39 
40  bool binary;
41 
42  ParseOptions po(usage);
43 
44  po.Register("binary", &binary, "Write output in binary mode.");
45 
46  po.Read(argc, argv);
47 
48  if (po.NumArgs() != 2) {
49  po.PrintUsage();
50  exit(1);
51  }
52 
53  std::string transition_model_rxfilename = po.GetArg(1),
54  transition_model_wxfilename = po.GetArg(2);
55 
56 
57  TransitionModel trans_model;
58  ReadKaldiObject(transition_model_rxfilename, &trans_model);
59 
60  WriteKaldiObject(trans_model, transition_model_wxfilename, binary);
61 
62  KALDI_LOG << "Copied transition model.";
63  } catch(const std::exception &e) {
64  std::cerr << e.what();
65  return -1;
66  }
67 }
68 
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
void PrintUsage(bool print_command_line=false)
Prints the usage documentation [provided in the constructor].
fst::StdArc StdArc
kaldi::int32 int32
void Register(const std::string &name, bool *ptr, const std::string &doc)
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
int Read(int argc, const char *const *argv)
Parses the command line options and fills the ParseOptions-registered variables.
int main(int argc, char *argv[])
std::string GetArg(int param) const
Returns one of the positional parameters; 1-based indexing for argc/argv compatibility.
int NumArgs() const
Number of positional parameters (c.f. argc-1).
void WriteKaldiObject(const C &c, const std::string &filename, bool binary)
Definition: kaldi-io.h:257
#define KALDI_LOG
Definition: kaldi-error.h:153