All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
process-pitch-feats.cc File Reference
Include dependency graph for process-pitch-feats.cc:

Go to the source code of this file.

Namespaces

 kaldi
 Relabels neural network egs with the read pdf-id alignments.
 

Functions

void ProcessPovFeatures (Matrix< BaseFloat > *mat)
 
void TakeLogOfPitch (Matrix< BaseFloat > *mat)
 
void SubtractMovingAverage (int32 normalization_window_size, Matrix< BaseFloat > *mat)
 
void SetToMovingAverage (int32 average_window_size, Matrix< BaseFloat > *mat)
 
int main (int argc, char *argv[])
 

Function Documentation

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

Definition at line 105 of file process-pitch-feats.cc.

References SequentialTableReader< Holder >::Done(), ParseOptions::GetArg(), KALDI_ASSERT, KALDI_ERR, KALDI_LOG, KALDI_VLOG, KALDI_WARN, SequentialTableReader< Holder >::Key(), SequentialTableReader< Holder >::Next(), ParseOptions::NumArgs(), MatrixBase< Real >::NumCols(), MatrixBase< Real >::NumRows(), TableWriter< Holder >::Open(), ParseOptions::PrintUsage(), kaldi::ProcessPovFeatures(), ParseOptions::Read(), ParseOptions::Register(), kaldi::SetToMovingAverage(), kaldi::SubtractMovingAverage(), kaldi::TakeLogOfPitch(), SequentialTableReader< Holder >::Value(), and TableWriter< Holder >::Write().

105  {
106  try {
107  using namespace kaldi;
108  const char *usage =
109  "This is a rather special-purpose program which processes 2-dimensional\n"
110  "features consisting of (prob-of-voicing, pitch) into something suitable\n"
111  "to put into a speech recognizer. First use interpolate-feats\n"
112  "Usage: process-pitch-feats [options...] <feats-rspecifier> <feats-wspecifier>\n";
113 
114 
115  // construct all the global objects
116  ParseOptions po(usage);
117 
118  int32 normalization_window_size = 151; // should be odd number
119  int32 average_window_size = 5;
120 
121  // Register the options
122  po.Register("normalization-window-size",
123  &normalization_window_size, "Size of window used for "
124  "moving window nomalization (must be odd).");
125  po.Register("average-window-size",
126  &average_window_size,
127  "Size of moving average window (must be odd).");
128 
129  // parse options (+filling the registered variables)
130  po.Read(argc, argv);
131 
132  if (po.NumArgs() != 2) {
133  po.PrintUsage();
134  exit(1);
135  }
136 
137  KALDI_ASSERT(average_window_size > 0 && average_window_size % 2 == 1 &&
138  "--average-window-size option must be an odd positive number.");
139  KALDI_ASSERT(normalization_window_size > 0 && normalization_window_size % 2 == 1 &&
140  "--normalization-window-size option must be an odd positive number.");
141 
142  std::string input_rspecifier = po.GetArg(1);
143  std::string output_wspecifier = po.GetArg(2);
144 
145  SequentialBaseFloatMatrixReader reader(input_rspecifier);
146  BaseFloatMatrixWriter kaldi_writer; // typedef to TableWriter<something>.
147 
148  if (!kaldi_writer.Open(output_wspecifier))
149  KALDI_ERR << "Could not initialize output with wspecifier "
150  << output_wspecifier;
151 
152  int32 num_done = 0, num_err = 0;
153 
154  for (; !reader.Done(); reader.Next()) {
155  std::string utt = reader.Key();
156  Matrix<BaseFloat> features = reader.Value();
157  int num_frames = features.NumRows();
158 
159  if (num_frames == 0 && features.NumCols() != 2) {
160  KALDI_WARN << "Feature file has bad size "
161  << features.NumRows() << " by " << features.NumCols();
162  num_err++;
163  continue;
164  }
165 
166  ProcessPovFeatures(&features);
167  TakeLogOfPitch(&features);
168  SubtractMovingAverage(normalization_window_size, &features);
169  SetToMovingAverage(average_window_size, &features);
170  kaldi_writer.Write(utt, features);
171  num_done++;
172 
173  if (num_done % 10 == 0)
174  KALDI_LOG << "Processed " << num_done << " utterances";
175  KALDI_VLOG(2) << "Processed features for key " << utt;
176  }
177  KALDI_LOG << "Done " << num_done << " utterances, " << num_err
178  << " with errors.";
179  return (num_done != 0 ? 0 : 1);
180  } catch(const std::exception &e) {
181  std::cerr << e.what();
182  return -1;
183  }
184 }
Relabels neural network egs with the read pdf-id alignments.
Definition: chain.dox:20
bool Open(const std::string &wspecifier)
void Write(const std::string &key, const T &value) const
void SubtractMovingAverage(int32 normalization_window_size, Matrix< BaseFloat > *mat)
A templated class for writing objects to an archive or script file; see The Table concept...
Definition: kaldi-table.h:366
void TakeLogOfPitch(Matrix< BaseFloat > *mat)
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:127
#define KALDI_WARN
Definition: kaldi-error.h:130
MatrixIndexT NumRows() const
Returns number of rows (or zero for emtpy matrix).
Definition: kaldi-matrix.h:58
MatrixIndexT NumCols() const
Returns number of columns (or zero for emtpy matrix).
Definition: kaldi-matrix.h:61
void ProcessPovFeatures(Matrix< BaseFloat > *mat)
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
#define KALDI_VLOG(v)
Definition: kaldi-error.h:136
#define KALDI_LOG
Definition: kaldi-error.h:133
void SetToMovingAverage(int32 average_window_size, Matrix< BaseFloat > *mat)