11// featbin/apply-cmvn.cc
22
33// Copyright 2009-2011 Microsoft Corporation
4+ // 2014 Johns Hopkins University
45
56// See ../../COPYING for clarification regarding multiple authors
67//
@@ -35,18 +36,24 @@ int main(int argc, char *argv[]) {
3536 ParseOptions po (usage);
3637 std::string utt2spk_rspecifier;
3738 bool norm_vars = false ;
39+ bool norm_means = true ;
3840 po.Register (" utt2spk" , &utt2spk_rspecifier, " rspecifier for utterance to speaker map" );
3941 po.Register (" norm-vars" , &norm_vars, " If true, normalize variances. Note: "
4042 " to turn off mean normalization also, it's generally easiest to "
4143 " compute 'fake' CMVN stats with zero/one mean/variance."
4244 " See the --fake option to compute_cmvn_stats.sh" );
45+ po.Register (" norm-means" , &norm_means, " You can set this to false to turn off mean "
46+ " normalization, or to compute 'fake' CMVN stats; "
47+ " see the --fake option to compute_cmvn_stats.sh" );
4348
4449 po.Read (argc, argv);
4550
4651 if (po.NumArgs () != 3 ) {
4752 po.PrintUsage ();
4853 exit (1 );
4954 }
55+ if (norm_vars && !norm_means)
56+ KALDI_ERR << " You cannot normalize the variance but not the mean." ;
5057
5158 kaldi::int32 num_done = 0 , num_err = 0 ;
5259
@@ -63,28 +70,31 @@ int main(int argc, char *argv[]) {
6370
6471 RandomAccessDoubleMatrixReaderMapped cmvn_reader (cmvn_rspecifier,
6572 utt2spk_rspecifier);
66-
67- for (;!feat_reader.Done (); feat_reader.Next ()) {
73+
74+ for (; !feat_reader.Done (); feat_reader.Next ()) {
6875 std::string utt = feat_reader.Key ();
6976 Matrix<BaseFloat> feat (feat_reader.Value ());
70-
71- if (!cmvn_reader.HasKey (utt)) {
72- KALDI_WARN << " No normalization statistics available for key "
73- << utt << " , producing no output for this utterance" ;
74- num_err++;
75- continue ;
77+ if (norm_means) {
78+ if (!cmvn_reader.HasKey (utt)) {
79+ KALDI_WARN << " No normalization statistics available for key "
80+ << utt << " , producing no output for this utterance" ;
81+ num_err++;
82+ continue ;
83+ }
84+ const Matrix<double > &cmvn_stats = cmvn_reader.Value (utt);
85+
86+ ApplyCmvn (cmvn_stats, norm_vars, &feat);
87+
88+ feat_writer.Write (utt, feat);
89+ } else {
90+ feat_writer.Write (utt, feat);
7691 }
77- const Matrix<double > &cmvn_stats = cmvn_reader.Value (utt);
78-
79- ApplyCmvn (cmvn_stats, norm_vars, &feat);
80-
81- feat_writer.Write (utt, feat);
8292 num_done++;
8393 }
8494 } else {
8595 if (utt2spk_rspecifier != " " )
8696 KALDI_ERR << " --utt2spk option not compatible with rxfilename as input "
87- << " (did you forget ark:?)" ;
97+ << " (did you forget ark:?)" ;
8898 std::string cmvn_rxfilename = cmvn_rspecifier_or_rxfilename;
8999 bool binary;
90100 Input ki (cmvn_rxfilename, &binary);
@@ -94,7 +104,8 @@ int main(int argc, char *argv[]) {
94104 for (;!feat_reader.Done (); feat_reader.Next ()) {
95105 std::string utt = feat_reader.Key ();
96106 Matrix<BaseFloat> feat (feat_reader.Value ());
97- ApplyCmvn (cmvn_stats, norm_vars, &feat);
107+ if (norm_means)
108+ ApplyCmvn (cmvn_stats, norm_vars, &feat);
98109 feat_writer.Write (utt, feat);
99110 num_done++;
100111 }
0 commit comments