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

References SequentialTableReader< Holder >::Done(), ParseOptions::GetArg(), SequentialTableReader< Holder >::Key(), SequentialTableReader< Holder >::Next(), ParseOptions::NumArgs(), ParseOptions::PrintUsage(), ParseOptions::Read(), 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 and writes a corresponding archive\n"
31  "that maps utterance-id to utterance length in frames, or (with\n"
32  "one argument) print to stdout the total number of frames in the\n"
33  "input archive.\n"
34  "Usage: feat-to-len [options] <in-rspecifier> [<out-wspecifier>]\n"
35  "e.g.: feat-to-len scp:feats.scp ark,t:feats.lengths\n"
36  "or: feat-to-len scp:feats.scp\n";
37 
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  if (po.NumArgs() == 2) {
48  std::string rspecifier = po.GetArg(1);
49  std::string wspecifier = po.GetArg(2);
50 
51  Int32Writer length_writer(wspecifier);
52 
53  SequentialBaseFloatMatrixReader matrix_reader(rspecifier);
54  for (; !matrix_reader.Done(); matrix_reader.Next())
55  length_writer.Write(matrix_reader.Key(), matrix_reader.Value().NumRows());
56  } else {
57  int64 tot = 0;
58  std::string rspecifier = po.GetArg(1);
59  SequentialBaseFloatMatrixReader matrix_reader(rspecifier);
60  for (; !matrix_reader.Done(); matrix_reader.Next())
61  tot += matrix_reader.Value().NumRows();
62  std::cout << tot << std::endl;
63  }
64  return 0;
65  } catch(const std::exception &e) {
66  std::cerr << e.what();
67  return -1;
68  }
69 }
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