feat-to-dim.cc
Go to the documentation of this file.
1 // featbin/feat-to-dim.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 
20 #include "base/kaldi-common.h"
21 #include "util/common-utils.h"
22 #include "matrix/kaldi-matrix.h"
23 
24 
25 int main(int argc, char *argv[]) {
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 }
68 
69 
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
int main(int argc, char *argv[])
Definition: feat-to-dim.cc:25
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
void Write(const std::string &key, const T &value) const
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
Definition: parse-options.h:36
std::ostream & Stream()
Definition: kaldi-io.cc:701
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.
#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.
WspecifierType ClassifyWspecifier(const std::string &wspecifier, std::string *archive_wxfilename, std::string *script_wxfilename, WspecifierOptions *opts)
Definition: kaldi-table.cc:135
int NumArgs() const
Number of positional parameters (c.f. argc-1).