29 using namespace kaldi;
32 "Apply cepstral mean and (optionally) variance normalization\n" 33 "Per-utterance by default, or per-speaker if utt2spk option provided\n" 34 "Usage: apply-cmvn [options] (<cmvn-stats-rspecifier>|<cmvn-stats-rxfilename>) <feats-rspecifier> <feats-wspecifier>\n" 35 "e.g.: apply-cmvn --utt2spk=ark:data/train/utt2spk scp:data/train/cmvn.scp scp:data/train/feats.scp ark:-\n" 36 "See also: modify-cmvn-stats, matrix-sum, compute-cmvn-stats\n";
39 std::string utt2spk_rspecifier;
40 bool norm_vars =
false;
41 bool norm_means =
true;
43 std::string skip_dims_str;
45 po.Register(
"utt2spk", &utt2spk_rspecifier,
46 "rspecifier for utterance to speaker map");
47 po.Register(
"norm-vars", &norm_vars,
"If true, normalize variances.");
48 po.Register(
"norm-means", &norm_means,
"You can set this to false to turn off mean " 49 "normalization. Note, the same can be achieved by using 'fake' CMVN stats; " 50 "see the --fake option to compute_cmvn_stats.sh");
51 po.Register(
"skip-dims", &skip_dims_str,
"Dimensions for which to skip " 52 "normalization: colon-separated list of integers, e.g. 13:14:15)");
53 po.Register(
"reverse", &reverse,
"If true, apply CMVN in a reverse sense, " 54 "so as to transform zero-mean, unit-variance input into data " 55 "with the given mean and variance.");
59 if (po.NumArgs() != 3) {
63 if (norm_vars && !norm_means)
64 KALDI_ERR <<
"You cannot normalize the variance but not the mean.";
67 std::string cmvn_rspecifier_or_rxfilename = po.GetArg(1);
68 std::string feat_rspecifier = po.GetArg(2);
69 std::string feat_wspecifier = po.GetArg(3);
77 for (;!reader.Done(); reader.Next()) {
78 writer.Write(reader.Key(), reader.Value());
81 KALDI_LOG <<
"Copied " << num_done <<
" utterances.";
82 return (num_done != 0 ? 0 : 1);
86 std::vector<int32> skip_dims;
90 KALDI_ERR <<
"Bad --skip-dims option (should be colon-separated list of " 102 std::string cmvn_rspecifier = cmvn_rspecifier_or_rxfilename;
107 for (; !feat_reader.Done(); feat_reader.Next()) {
108 std::string utt = feat_reader.Key();
111 if (!cmvn_reader.HasKey(utt)) {
112 KALDI_WARN <<
"No normalization statistics available for key " 113 << utt <<
", producing no output for this utterance";
118 if (!skip_dims.empty())
126 feat_writer.Write(utt, feat);
128 feat_writer.Write(utt, feat);
133 if (utt2spk_rspecifier !=
"")
134 KALDI_ERR <<
"--utt2spk option not compatible with rxfilename as input " 135 <<
"(did you forget ark:?)";
136 std::string cmvn_rxfilename = cmvn_rspecifier_or_rxfilename;
138 Input ki(cmvn_rxfilename, &binary);
140 cmvn_stats.
Read(ki.Stream(), binary);
141 if (!skip_dims.empty())
144 for (;!feat_reader.Done(); feat_reader.Next()) {
145 std::string utt = feat_reader.Key();
154 feat_writer.Write(utt, feat);
159 KALDI_LOG <<
"Applied cepstral mean and variance normalization to " 160 << num_done <<
" utterances, errors on " << num_err;
162 KALDI_LOG <<
"Applied cepstral mean normalization to " 163 << num_done <<
" utterances, errors on " << num_err;
164 return (num_done != 0 ? 0 : 1);
165 }
catch(
const std::exception &e) {
166 std::cerr << e.what();
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
bool SplitStringToIntegers(const std::string &full, const char *delim, bool omit_empty_strings, std::vector< I > *out)
Split a string (e.g.
This class is for when you are reading something in random access, but it may actually be stored per-...
A templated class for writing objects to an archive or script file; see The Table concept...
RspecifierType ClassifyRspecifier(const std::string &rspecifier, std::string *rxfilename, RspecifierOptions *opts)
void ApplyCmvnReverse(const MatrixBase< double > &stats, bool var_norm, MatrixBase< BaseFloat > *feats)
This is as ApplyCmvn, but does so in the reverse sense, i.e.
void Read(std::istream &in, bool binary, bool add=false)
read from stream.
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
void ApplyCmvn(const MatrixBase< double > &stats, bool var_norm, MatrixBase< BaseFloat > *feats)
Apply cepstral mean and variance normalization to a matrix of features.
void FakeStatsForSomeDims(const std::vector< int32 > &dims, MatrixBase< double > *stats)
Modify the stats so that for some dimensions (specified in "dims"), we replace them with "fake" stats...