fmpe-sum-accs.cc
Go to the documentation of this file.
1 // featbin/fmpe-sum-accs.cc
2 
3 // Copyright 2012 Johns Hopkins University (Author: Daniel Povey)
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 "transform/fmpe.h"
23 
24 int main(int argc, char *argv[]) {
25  using namespace kaldi;
26  using kaldi::int32;
27  try {
28  const char *usage =
29  "Sum fMPE stats\n"
30  "Usage: fmpe-sum-accs [options...] <accs-out> <stats-in1> <stats-in2> ... \n"
31  "E.g. fmpe-sum-accs 1.accs 1.1.accs 1.2.accs 1.3.accs 1.4.accs\n";
32 
33  ParseOptions po(usage);
34  bool binary = true;
35  po.Register("binary", &binary, "If true, output fMPE stats in "
36  "binary mode.");
37  po.Read(argc, argv);
38 
39  if (po.NumArgs() < 2) {
40  po.PrintUsage();
41  exit(1);
42  }
43 
44  std::string stats_wxfilename = po.GetArg(1);
45 
46  FmpeStats stats;
47  for (int32 arg = 2; arg <= po.NumArgs(); arg++) {
48  std::string stats_rxfilename = po.GetArg(arg);
49  bool binary;
50  Input ki(stats_rxfilename, &binary);
51  stats.Read(ki.Stream(), binary, true); // true == sum accs.
52  }
53 
54  WriteKaldiObject(stats, stats_wxfilename, binary);
55 
56  KALDI_LOG << "Summed " << (po.NumArgs()-1) << " fMPE stats and wrote to "
57  << stats_wxfilename;
58  return 0;
59  } catch(const std::exception &e) {
60  std::cerr << e.what();
61  return -1;
62  }
63 }
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].
kaldi::int32 int32
int main(int argc, char *argv[])
void Register(const std::string &name, bool *ptr, const std::string &doc)
std::istream & Stream()
Definition: kaldi-io.cc:826
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
Definition: parse-options.h:36
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).
void WriteKaldiObject(const C &c, const std::string &filename, bool binary)
Definition: kaldi-io.h:257
#define KALDI_LOG
Definition: kaldi-error.h:153
void Read(std::istream &is, bool binary, bool add=false)
Definition: fmpe.cc:685