32 if (!weights_reader->
IsOpen()) {
36 if (!weights_reader->
HasKey(utt)) {
37 KALDI_WARN <<
"No weights available for utterance " << utt;
42 KALDI_WARN <<
"Weights for utterance " << utt <<
" have wrong dimension " 43 << weights.
Dim() <<
" vs. " << feats.
NumRows();
54 int main(
int argc,
char *argv[]) {
56 using namespace kaldi;
60 "Compute cepstral mean and variance normalization statistics\n" 61 "If wspecifier provided: per-utterance by default, or per-speaker if\n" 62 "spk2utt option provided; if wxfilename: global\n" 63 "Usage: compute-cmvn-stats [options] <feats-rspecifier> (<stats-wspecifier>|<stats-wxfilename>)\n" 64 "e.g.: compute-cmvn-stats --spk2utt=ark:data/train/spk2utt" 65 " scp:data/train/feats.scp ark,scp:/foo/bar/cmvn.ark,data/train/cmvn.scp\n" 66 "See also: apply-cmvn, modify-cmvn-stats\n";
69 std::string spk2utt_rspecifier, weights_rspecifier;
71 po.
Register(
"spk2utt", &spk2utt_rspecifier,
"rspecifier for speaker to utterance-list map");
72 po.
Register(
"binary", &binary,
"write in binary mode (applies only to global CMN/CVN)");
73 po.
Register(
"weights", &weights_rspecifier,
"rspecifier for a vector of floats " 74 "for each utterance, that's a per-frame weight.");
83 int32 num_done = 0, num_err = 0;
84 std::string rspecifier = po.
GetArg(1);
85 std::string wspecifier_or_wxfilename = po.
GetArg(2);
91 std::string wspecifier = wspecifier_or_wxfilename;
95 if (spk2utt_rspecifier !=
"") {
99 for (; !spk2utt_reader.
Done(); spk2utt_reader.
Next()) {
100 std::string spk = spk2utt_reader.
Key();
101 const std::vector<std::string> &uttlist = spk2utt_reader.
Value();
102 bool is_init =
false;
104 for (
size_t i = 0;
i < uttlist.size();
i++) {
105 std::string utt = uttlist[
i];
106 if (!feat_reader.
HasKey(utt)) {
107 KALDI_WARN <<
"Did not find features for utterance " << utt;
123 KALDI_WARN <<
"No stats accumulated for speaker " << spk;
125 writer.
Write(spk, stats);
131 for (; !feat_reader.
Done(); feat_reader.
Next()) {
132 std::string utt = feat_reader.
Key();
141 writer.
Write(feat_reader.
Key(), stats);
146 if (spk2utt_rspecifier !=
"")
147 KALDI_ERR <<
"--spk2utt option not compatible with wxfilename as output " 148 <<
"(did you forget ark:?)";
149 std::string wxfilename = wspecifier_or_wxfilename;
150 bool is_init =
false;
153 for (; !feat_reader.
Done(); feat_reader.
Next()) {
154 std::string utt = feat_reader.
Key();
168 KALDI_LOG <<
"Wrote global CMVN stats to " 171 KALDI_LOG <<
"Done accumulating CMVN stats for " << num_done
172 <<
" utterances; " << num_err <<
" had errors.";
173 return (num_done != 0 ? 0 : 1);
174 }
catch(
const std::exception &e) {
175 std::cerr << e.what();
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
bool AccCmvnStatsWrapper(const std::string &utt, const MatrixBase< BaseFloat > &feats, RandomAccessBaseFloatVectorReader *weights_reader, Matrix< double > *cmvn_stats)
MatrixIndexT NumCols() const
Returns number of columns (or zero for empty matrix).
Base class which provides matrix operations not involving resizing or allocation. ...
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...
void Write(const std::string &key, const T &value) const
void Register(const std::string &name, bool *ptr, const std::string &doc)
Allows random access to a collection of objects in an archive or script file; see The Table concept...
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
const T & Value(const std::string &key)
void InitCmvnStats(int32 dim, Matrix< double > *stats)
This function initializes the matrix to dimension 2 by (dim+1); 1st "dim" elements of 1st row are mea...
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
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.
MatrixIndexT Dim() const
Returns the dimension of the vector.
bool HasKey(const std::string &key)
void AccCmvnStats(const VectorBase< BaseFloat > &feats, BaseFloat weight, MatrixBase< double > *stats)
Accumulation from a single frame (weighted).
WspecifierType ClassifyWspecifier(const std::string &wspecifier, std::string *archive_wxfilename, std::string *script_wxfilename, WspecifierOptions *opts)
int NumArgs() const
Number of positional parameters (c.f. argc-1).
A class representing a vector.
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
void WriteKaldiObject(const C &c, const std::string &filename, bool binary)
std::string PrintableWxfilename(const std::string &wxfilename)
PrintableWxfilename turns the wxfilename into a more human-readable form for error reporting...
int main(int argc, char *argv[])