26 int main(
int argc,
char *argv[]) {
28 using namespace kaldi;
31 "Copy cepstral mean/variance stats so that some dimensions have 'fake' stats\n" 32 "that will skip normalization\n" 33 "Usage: modify-cmvn-stats [options] [<fake-dims>] <in-rspecifier> <out-wspecifier>\n" 34 "e.g.: modify-cmvn-stats 13:14:15 ark:- ark:-\n" 35 "or: modify-cmvn-stats --convert-to-mean-and-var=true ark:- ark:-\n" 36 "See also: compute-cmvn-stats\n";
38 bool convert_to_mean_and_var =
false;
42 po.
Register(
"convert-to-mean-and-var", &convert_to_mean_and_var,
43 "If true, convert the stats to a matrix containing the mean " 44 "and the centered variance in each dimension");
56 std::string skip_dims_str, rspecifier, wspecifier;
58 skip_dims_str = po.
GetArg(1);
66 std::vector<int32> skip_dims;
68 KALDI_ERR <<
"Bad first argument (should be colon-separated list of " 75 for (; !reader.
Done(); reader.
Next()) {
78 if (mat.NumRows() != 2)
79 KALDI_ERR <<
"Expected input to be CMVN stats (should have two rows)";
82 if (!convert_to_mean_and_var) {
86 int32 dim = mat.NumCols() - 1;
87 double count = mat(0, dim);
90 KALDI_WARN <<
"Zero or negative count for speaker " << reader.
Key()
91 <<
", not outputting mean and variance stats.";
95 double mean = mat(0,
i) /
count,
96 variance = mat(1,
i) / count - mean * mean;
97 modified_mat(0,
i) = mean;
98 modified_mat(1,
i) = variance;
100 writer.
Write(reader.
Key(), modified_mat);
104 KALDI_LOG <<
"Modified " << num_done <<
" sets of stats.";
105 return (num_done != 0 ? 0 : 1);
106 }
catch(
const std::exception &e) {
107 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.
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)
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
int main(int argc, char *argv[])
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.
int NumArgs() const
Number of positional parameters (c.f. argc-1).
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...