compute-and-process-kaldi-pitch-feats.cc File Reference
Include dependency graph for compute-and-process-kaldi-pitch-feats.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 27 of file compute-and-process-kaldi-pitch-feats.cc.

References kaldi::ComputeAndProcessKaldiPitch(), WaveData::Data(), 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 >::NumRows(), ParseOptions::PrintUsage(), ParseOptions::Read(), PitchExtractionOptions::Register(), ProcessPitchOptions::Register(), PitchExtractionOptions::samp_freq, WaveData::SampFreq(), SequentialTableReader< Holder >::Value(), and TableWriter< Holder >::Write().

27  {
28  try {
29  using namespace kaldi;
30  const char *usage =
31  "Apply Kaldi pitch extractor and pitch post-processor, starting from wav input.\n"
32  "Equivalent to compute-kaldi-pitch-feats | process-kaldi-pitch-feats, except\n"
33  "that it is able to simulate online pitch extraction; see options like\n"
34  "--frames-per-chunk, --simulate-first-pass-online, --recompute-frame.\n"
35  "\n"
36  "Usage: compute-and-process-kaldi-pitch-feats [options...] <wav-rspecifier> <feats-wspecifier>\n"
37  "e.g.\n"
38  "compute-and-process-kaldi-pitch-feats --simulate-first-pass-online=true \\\n"
39  " --frames-per-chunk=10 --sample-frequency=8000 scp:wav.scp ark:- \n"
40  "See also: compute-kaldi-pitch-feats, process-kaldi-pitch-feats\n";
41 
42  ParseOptions po(usage);
43  PitchExtractionOptions pitch_opts;
44  ProcessPitchOptions process_opts;
45 
46  int32 channel = -1; // Note: this isn't configurable because it's not a very
47  // good idea to control it this way: better to extract the
48  // on the command line (in the .scp file) using sox or
49  // similar.
50 
51  pitch_opts.Register(&po);
52  process_opts.Register(&po);
53 
54  po.Read(argc, argv);
55 
56  if (po.NumArgs() != 2) {
57  po.PrintUsage();
58  exit(1);
59  }
60 
61  std::string wav_rspecifier = po.GetArg(1),
62  feat_wspecifier = po.GetArg(2);
63 
64  SequentialTableReader<WaveHolder> wav_reader(wav_rspecifier);
65  BaseFloatMatrixWriter feat_writer(feat_wspecifier);
66 
67  int32 num_done = 0, num_err = 0;
68  for (; !wav_reader.Done(); wav_reader.Next()) {
69  std::string utt = wav_reader.Key();
70  const WaveData &wave_data = wav_reader.Value();
71 
72  int32 num_chan = wave_data.Data().NumRows(), this_chan = channel;
73  {
74  KALDI_ASSERT(num_chan > 0);
75  // reading code if no channels.
76  if (channel == -1) {
77  this_chan = 0;
78  if (num_chan != 1)
79  KALDI_WARN << "Channel not specified but you have data with "
80  << num_chan << " channels; defaulting to zero";
81  } else {
82  if (this_chan >= num_chan) {
83  KALDI_WARN << "File with id " << utt << " has "
84  << num_chan << " channels but you specified channel "
85  << channel << ", producing no output.";
86  continue;
87  }
88  }
89  }
90 
91  if (pitch_opts.samp_freq != wave_data.SampFreq())
92  KALDI_ERR << "Sample frequency mismatch: you specified "
93  << pitch_opts.samp_freq << " but data has "
94  << wave_data.SampFreq() << " (use --sample-frequency option)";
95 
96 
97  SubVector<BaseFloat> waveform(wave_data.Data(), this_chan);
98  Matrix<BaseFloat> features;
99  try {
100  ComputeAndProcessKaldiPitch(pitch_opts, process_opts,
101  waveform, &features);
102  } catch (...) {
103  KALDI_WARN << "Failed to compute pitch for utterance "
104  << utt;
105  num_err++;
106  continue;
107  }
108 
109  feat_writer.Write(utt, features);
110  if (num_done % 50 == 0 && num_done != 0)
111  KALDI_VLOG(2) << "Processed " << num_done << " utterances";
112  num_done++;
113  }
114  KALDI_LOG << "Done " << num_done << " utterances, " << num_err
115  << " with errors.";
116  return (num_done != 0 ? 0 : 1);
117  } catch(const std::exception &e) {
118  std::cerr << e.what();
119  return -1;
120  }
121 }
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
BaseFloat SampFreq() const
Definition: wave-reader.h:126
const Matrix< BaseFloat > & Data() const
Definition: wave-reader.h:124
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
void ComputeAndProcessKaldiPitch(const PitchExtractionOptions &pitch_opts, const ProcessPitchOptions &process_opts, const VectorBase< BaseFloat > &wave, Matrix< BaseFloat > *output)
This function combines ComputeKaldiPitch and ProcessPitch.
#define KALDI_ERR
Definition: kaldi-error.h:147
#define KALDI_WARN
Definition: kaldi-error.h:150
void Register(OptionsItf *opts)
This class&#39;s purpose is to read in Wave files.
Definition: wave-reader.h:106
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
Definition: kaldi-matrix.h:64
#define KALDI_VLOG(v)
Definition: kaldi-error.h:156
#define KALDI_LOG
Definition: kaldi-error.h:153
Represents a non-allocating general vector which can be defined as a sub-vector of higher-level vecto...
Definition: kaldi-vector.h:501
void Register(ParseOptions *opts)