feat-to-dim.cc File Reference
Include dependency graph for feat-to-dim.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 feat-to-dim.cc.

References kaldi::ClassifyWspecifier(), SequentialTableReader< Holder >::Done(), ParseOptions::GetArg(), KALDI_ERR, SequentialTableReader< Holder >::Key(), kaldi::kNoWspecifier, SequentialTableReader< Holder >::Next(), ParseOptions::NumArgs(), ParseOptions::PrintUsage(), ParseOptions::Read(), Output::Stream(), SequentialTableReader< Holder >::Value(), and TableWriter< Holder >::Write().

25  {
26  try {
27  using namespace kaldi;
28 
29  const char *usage =
30  "Reads an archive of features. If second argument is wxfilename, writes\n"
31  "the feature dimension of the first feature file; if second argument is\n"
32  "wspecifier, writes an archive of the feature dimension, indexed by utterance\n"
33  "id.\n"
34  "Usage: feat-to-dim [options] <feat-rspecifier> (<dim-wspecifier>|<dim-wxfilename>)\n"
35  "e.g.: feat-to-dim scp:feats.scp -\n";
36 
37  ParseOptions po(usage);
38 
39  po.Read(argc, argv);
40 
41  if (po.NumArgs() != 2) {
42  po.PrintUsage();
43  exit(1);
44  }
45 
46  std::string rspecifier = po.GetArg(1);
47  std::string wspecifier_or_wxfilename = po.GetArg(2);
48 
49  SequentialBaseFloatMatrixReader kaldi_reader(rspecifier);
50 
51  if (ClassifyWspecifier(wspecifier_or_wxfilename, NULL, NULL, NULL)
52  != kNoWspecifier) {
53  Int32Writer dim_writer(wspecifier_or_wxfilename);
54  for (; !kaldi_reader.Done(); kaldi_reader.Next())
55  dim_writer.Write(kaldi_reader.Key(), kaldi_reader.Value().NumCols());
56  } else {
57  if (kaldi_reader.Done())
58  KALDI_ERR << "Could not read any features (empty archive?)";
59  Output ko(wspecifier_or_wxfilename, false); // text mode.
60  ko.Stream() << kaldi_reader.Value().NumCols() << "\n";
61  }
62  return 0;
63  } catch(const std::exception &e) {
64  std::cerr << e.what();
65  return -1;
66  }
67 }
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
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_ERR
Definition: kaldi-error.h:147
WspecifierType ClassifyWspecifier(const std::string &wspecifier, std::string *archive_wxfilename, std::string *script_wxfilename, WspecifierOptions *opts)
Definition: kaldi-table.cc:135