ali-to-pdf.cc
Go to the documentation of this file.
1 // bin/ali-to-pdf.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 
22 #include "base/kaldi-common.h"
23 #include "gmm/am-diag-gmm.h"
24 #include "hmm/transition-model.h"
25 #include "hmm/hmm-utils.h"
26 #include "util/common-utils.h"
27 #include "fst/fstlib.h"
28 
29 int main(int argc, char *argv[]) {
30  using namespace kaldi;
31  typedef kaldi::int32 int32;
32  try {
33  const char *usage =
34  "Converts alignments (containing transition-ids) to pdf-ids, zero-based.\n"
35  "Usage: ali-to-pdf [options] <model> <alignments-rspecifier> <pdfs-wspecifier>\n"
36  "e.g.: \n"
37  " ali-to-pdf 1.mdl ark:1.ali ark,t:-\n";
38  ParseOptions po(usage);
39 
40  po.Read(argc, argv);
41 
42  if (po.NumArgs() != 3) {
43  po.PrintUsage();
44  exit(1);
45  }
46 
47  std::string model_filename = po.GetArg(1),
48  alignments_rspecifier = po.GetArg(2),
49  pdfs_wspecifier = po.GetArg(3);
50 
51  TransitionModel trans_model;
52  ReadKaldiObject(model_filename, &trans_model);
53 
54  SequentialInt32VectorReader reader(alignments_rspecifier);
55 
56  Int32VectorWriter writer(pdfs_wspecifier);
57  int32 num_done = 0;
58  for (; !reader.Done(); reader.Next()) {
59  std::string key = reader.Key();
60  std::vector<int32> alignment = reader.Value();
61 
62  for (size_t i = 0; i < alignment.size(); i++)
63  alignment[i] = trans_model.TransitionIdToPdf(alignment[i]);
64 
65  writer.Write(key, alignment);
66  num_done++;
67  }
68  KALDI_LOG << "Converted " << num_done << " alignments to pdf sequences.";
69  } catch(const std::exception &e) {
70  std::cerr << e.what();
71  return -1;
72  }
73 }
74 
75 
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].
A templated class for writing objects to an archive or script file; see The Table concept...
Definition: kaldi-table.h:368
kaldi::int32 int32
int32 TransitionIdToPdf(int32 trans_id) const
void Write(const std::string &key, const T &value) const
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
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
Definition: kaldi-table.h:287
int Read(int argc, const char *const *argv)
Parses the command line options and fills the ParseOptions-registered variables.
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).
int main(int argc, char *argv[])
Converts alignments (containing transition-ids) to pdf-ids, zero-based.
Definition: ali-to-pdf.cc:29
#define KALDI_LOG
Definition: kaldi-error.h:153