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.");
78 if (po.NumArgs() != 2) {
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).
A templated class for writing objects to an archive or script file; see The Table concept...
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...
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...
WspecifierType ClassifyWspecifier(const std::string &wspecifier, std::string *archive_wxfilename, std::string *script_wxfilename, WspecifierOptions *opts)
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...