ali-to-pdf.cc File Reference
#include "base/kaldi-common.h"
#include "gmm/am-diag-gmm.h"
#include "hmm/transition-model.h"
#include "hmm/hmm-utils.h"
#include "util/common-utils.h"
#include "fst/fstlib.h"
Include dependency graph for ali-to-pdf.cc:

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 Converts alignments (containing transition-ids) to pdf-ids, zero-based. More...
 

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Converts alignments (containing transition-ids) to pdf-ids, zero-based.

Definition at line 29 of file ali-to-pdf.cc.

References SequentialTableReader< Holder >::Done(), ParseOptions::GetArg(), rnnlm::i, KALDI_LOG, SequentialTableReader< Holder >::Key(), SequentialTableReader< Holder >::Next(), ParseOptions::NumArgs(), ParseOptions::PrintUsage(), ParseOptions::Read(), kaldi::ReadKaldiObject(), TransitionModel::TransitionIdToPdf(), SequentialTableReader< Holder >::Value(), and TableWriter< Holder >::Write().

29  {
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 }
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
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 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
#define KALDI_LOG
Definition: kaldi-error.h:153