make-pdf-to-tid-transducer.cc
Go to the documentation of this file.
1 // bin/make-pdf-to-tid-transducer.cc
2 // Copyright 2009-2011 Microsoft Corporation
3 
4 // See ../../COPYING for clarification regarding multiple authors
5 //
6 // Licensed under the Apache License, Version 2.0 (the "License");
7 // you may not use this file except in compliance with the License.
8 // You may obtain a copy of the License at
9 //
10 // http://www.apache.org/licenses/LICENSE-2.0
11 //
12 // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
13 // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
14 // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
15 // MERCHANTABLITY OR NON-INFRINGEMENT.
16 // See the Apache 2 License for the specific language governing permissions and
17 // limitations under the License.
18 
19 #include "hmm/transition-model.h"
20 #include "hmm/hmm-utils.h"
21 #include "util/common-utils.h"
22 #include "fst/fstlib.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  "Make transducer from pdfs to transition-ids\n"
35  "Usage: make-pdf-to-tid-transducer model-filename [fst-out]\n"
36  "e.g.: \n"
37  " make-pdf-to-tid-transducer 1.mdl > pdf2tid.fst\n";
38  ParseOptions po(usage);
39 
40  po.Read(argc, argv);
41 
42  if (po.NumArgs() <1 || po.NumArgs() > 2) {
43  po.PrintUsage();
44  exit(1);
45  }
46 
47  std::string trans_model_filename = po.GetArg(1);
48  std::string fst_out_filename = po.GetOptArg(2);
49 
50  TransitionModel trans_model;
51  ReadKaldiObject(trans_model_filename, &trans_model);
52 
53  fst::VectorFst<fst::StdArc> *fst = GetPdfToTransitionIdTransducer(trans_model);
54 
55 #if _MSC_VER
56  if (fst_out_filename == "")
57  _setmode(_fileno(stdout), _O_BINARY);
58 #endif
59 
60  if (!fst->Write(fst_out_filename))
61  KALDI_ERR << "Error writing fst to "
62  << (fst_out_filename == "" ? "standard output" : fst_out_filename);
63  delete fst;
64  } catch(const std::exception &e) {
65  std::cerr << e.what();
66  return -1;
67  }
68 }
69 
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
For an extended explanation of the framework of which grammar-fsts are a part, please see Support for...
Definition: graph.dox:21
void PrintUsage(bool print_command_line=false)
Prints the usage documentation [provided in the constructor].
fst::StdArc StdArc
kaldi::int32 int32
int main(int argc, char *argv[])
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.
#define KALDI_ERR
Definition: kaldi-error.h:147
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).
std::string GetOptArg(int param) const
fst::VectorFst< fst::StdArc > * GetPdfToTransitionIdTransducer(const TransitionModel &trans_model)
Returns a transducer from pdfs plus one (input) to transition-ids (output).
Definition: hmm-utils.cc:407