append-vector-to-feats.cc File Reference
Include dependency graph for append-vector-to-feats.cc:

Go to the source code of this file.

Namespaces

 kaldi
 This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for mispronunciations detection tasks, the reference:
 

Functions

void AppendVectorToFeats (const Matrix< BaseFloat > &in, const Vector< BaseFloat > &vec, Matrix< BaseFloat > *out)
 
int main (int argc, char *argv[])
 

Function Documentation

◆ main()

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

Definition at line 42 of file append-vector-to-feats.cc.

References kaldi::AppendVectorToFeats(), kaldi::ClassifyRspecifier(), SequentialTableReader< Holder >::Done(), ParseOptions::GetArg(), RandomAccessTableReader< Holder >::HasKey(), KALDI_LOG, KALDI_VLOG, KALDI_WARN, SequentialTableReader< Holder >::Key(), kaldi::kNoRspecifier, SequentialTableReader< Holder >::Next(), ParseOptions::NumArgs(), ParseOptions::PrintUsage(), ParseOptions::Read(), kaldi::ReadKaldiObject(), ParseOptions::Register(), RandomAccessTableReader< Holder >::Value(), SequentialTableReader< Holder >::Value(), TableWriter< Holder >::Write(), and kaldi::WriteKaldiObject().

42  {
43  try {
44  using namespace kaldi;
45  using namespace std;
46 
47  const char *usage =
48  "Append a vector to each row of input feature files\n"
49  "\n"
50  "Usage: append-vector-to-feats <in-rspecifier1> <in-rspecifier2> <out-wspecifier>\n"
51  " or: append-vector-to-feats <in-rxfilename1> <in-rxfilename2> <out-wxfilename>\n"
52  "See also: paste-feats, concat-feats\n";
53 
54  ParseOptions po(usage);
55 
56  bool binary = true;
57  po.Register("binary", &binary, "If true, output files in binary "
58  "(only relevant for single-file operation, i.e. no tables)");
59 
60  po.Read(argc, argv);
61 
62  if (po.NumArgs() != 3) {
63  po.PrintUsage();
64  exit(1);
65  }
66 
67  if (ClassifyRspecifier(po.GetArg(1), NULL, NULL)
68  != kNoRspecifier) {
69  // We're operating on tables, e.g. archives.
70 
71 
72  string feat_rspecifier = po.GetArg(1);
73  SequentialBaseFloatMatrixReader feat_reader(feat_rspecifier);
74 
75  string vec_rspecifier = po.GetArg(2);
76  RandomAccessBaseFloatVectorReader vec_reader(vec_rspecifier);
77 
78  string wspecifier = po.GetArg(3);
79  BaseFloatMatrixWriter feat_writer(wspecifier);
80 
81  int32 num_done = 0, num_err = 0;
82  // Main loop
83  for (; !feat_reader.Done(); feat_reader.Next()) {
84  string utt = feat_reader.Key();
85  KALDI_VLOG(2) << "Processing utterance " << utt;
86 
87  const Matrix<BaseFloat> &feats(feat_reader.Value());
88 
89  if (!vec_reader.HasKey(utt)) {
90  KALDI_WARN << "Could not read vector for utterance " << utt;
91  num_err++;
92  continue;
93  }
94  const Vector<BaseFloat> &vec(vec_reader.Value(utt));
95 
96  Matrix<BaseFloat> output;
97  AppendVectorToFeats(feats, vec, &output);
98  feat_writer.Write(utt, output);
99  num_done++;
100  }
101  KALDI_LOG << "Done " << num_done << " utts, errors on "
102  << num_err;
103 
104  return (num_done == 0 ? -1 : 0);
105  } else {
106  // We're operating on rxfilenames|wxfilenames, most likely files.
107  Matrix<BaseFloat> mat;
108  ReadKaldiObject(po.GetArg(1), &mat);
109  Vector<BaseFloat> vec;
110  ReadKaldiObject(po.GetArg(2), &vec);
111  Matrix<BaseFloat> output;
112  AppendVectorToFeats(mat, vec, &output);
113  std::string output_wxfilename = po.GetArg(3);
114  WriteKaldiObject(output, output_wxfilename, binary);
115  KALDI_LOG << "Wrote appended features to " << output_wxfilename;
116  return 0;
117  }
118  } catch(const std::exception &e) {
119  std::cerr << e.what();
120  return -1;
121  }
122 }
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
RspecifierType ClassifyRspecifier(const std::string &rspecifier, std::string *rxfilename, RspecifierOptions *opts)
Definition: kaldi-table.cc:225
void ReadKaldiObject(const std::string &filename, Matrix< float > *m)
Definition: kaldi-io.cc:832
Allows random access to a collection of objects in an archive or script file; see The Table concept...
Definition: kaldi-table.h:233
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_WARN
Definition: kaldi-error.h:150
A class representing a vector.
Definition: kaldi-vector.h:406
#define KALDI_VLOG(v)
Definition: kaldi-error.h:156
void WriteKaldiObject(const C &c, const std::string &filename, bool binary)
Definition: kaldi-io.h:257
void AppendVectorToFeats(const Matrix< BaseFloat > &in, const Vector< BaseFloat > &vec, Matrix< BaseFloat > *out)
#define KALDI_LOG
Definition: kaldi-error.h:153