60 using namespace kaldi;
62 "Estimate SGMM speaker vectors, either per utterance or for the " 63 "supplied set of speakers (with spk2utt option).\n" 64 "Reads Gaussian-level posteriors. Writes to a table of vectors.\n" 65 "Usage: sgmm2-est-spkvecs-gpost [options] <model-in> <feature-rspecifier> " 66 "<gpost-rspecifier> <vecs-wspecifier>\n";
69 string spk2utt_rspecifier, spkvecs_rspecifier;
73 po.Register(
"spk2utt", &spk2utt_rspecifier,
74 "File to read speaker to utterance-list map from.");
75 po.Register(
"spkvec-min-count", &min_count,
76 "Minimum count needed to estimate speaker vectors");
77 po.Register(
"rand-prune", &rand_prune,
"Randomized pruning parameter for posteriors (more->faster).");
78 po.Register(
"spk-vecs", &spkvecs_rspecifier,
"Speaker vectors to use during aligment (rspecifier)");
81 if (po.NumArgs() != 4) {
86 string model_rxfilename = po.GetArg(1),
87 feature_rspecifier = po.GetArg(2),
88 gpost_rspecifier = po.GetArg(3),
89 vecs_wspecifier = po.GetArg(4);
95 Input ki(model_rxfilename, &binary);
96 trans_model.
Read(ki.Stream(), binary);
97 am_sgmm.
Read(ki.Stream(), binary);
107 double tot_impr = 0.0, tot_t = 0.0;
108 int32 num_done = 0, num_err = 0;
110 if (!spk2utt_rspecifier.empty()) {
114 for (; !spk2utt_reader.Done(); spk2utt_reader.Next()) {
116 string spk = spk2utt_reader.Key();
117 const vector<string> &uttlist = spk2utt_reader.Value();
120 if (spkvecs_reader.IsOpen()) {
121 if (spkvecs_reader.HasKey(spk)) {
125 KALDI_WARN <<
"Cannot find speaker vector for " << spk;
129 for (
size_t i = 0;
i < uttlist.size();
i++) {
130 std::string utt = uttlist[
i];
131 if (!feature_reader.HasKey(utt)) {
132 KALDI_WARN <<
"Did not find features for utterance " << utt;
136 if (!gpost_reader.HasKey(utt) ||
137 gpost_reader.Value(utt).size() != feats.
NumRows()) {
138 KALDI_WARN <<
"Did not find posteriors for utterance " << utt
139 <<
" (or wrong size).";
146 &spk_vars, &spk_stats);
155 spk_stats.Update(am_sgmm, min_count, &spk_vec, &impr, &spk_tot_t);
156 vecs_writer.Write(spk, spk_vec);
158 KALDI_LOG <<
"For speaker " << spk <<
", auxf-impr from speaker vector is " 159 << (impr/spk_tot_t) <<
", over " << spk_tot_t <<
" frames.\n";
165 for (; !feature_reader.Done(); feature_reader.Next()) {
166 string utt = feature_reader.Key();
168 if (!gpost_reader.HasKey(utt) ||
169 gpost_reader.Value(utt).size() != feats.
NumRows()) {
170 KALDI_WARN <<
"Did not find posts for utterance " 178 if (spkvecs_reader.IsOpen()) {
179 if (spkvecs_reader.HasKey(utt)) {
183 KALDI_WARN <<
"Cannot find speaker vector for " << utt;
191 &spk_vars, &spk_stats);
198 spk_stats.Update(am_sgmm, min_count, &spk_vec, &impr, &utt_tot_t);
199 vecs_writer.Write(utt, spk_vec);
201 KALDI_LOG <<
"For utterance " << utt <<
", auxf-impr from speaker vectors is " 202 << (impr/utt_tot_t) <<
", over " << utt_tot_t <<
" frames.";
208 KALDI_LOG <<
"Done " << num_done <<
" files, " << num_err
210 KALDI_LOG <<
"Overall auxf impr per frame is " << (tot_impr / tot_t)
211 <<
" over " << tot_t <<
" frames.";
212 return (num_done != 0 ? 0 : 1);
213 }
catch(
const std::exception &e) {
214 std::cerr << e.what();
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Class for definition of the subspace Gmm acoustic model.
Class for the accumulators required to update the speaker vectors v_s.
const Vector< BaseFloat > & GetSpeakerVector()
void Read(std::istream &is, bool binary)
void AccumulateForUtterance(const Matrix< BaseFloat > &feats, const GaussPost &gpost, const TransitionModel &trans_model, const AmDiagGmm &am_gmm, FmllrDiagGmmAccs *spk_stats)
A templated class for writing objects to an archive or script file; see The Table concept...
void ComputePerSpkDerivedVars(Sgmm2PerSpkDerivedVars *vars) const
Computes the per-speaker derived vars; assumes vars->v_s is already set up.
Allows random access to a collection of objects in an archive or script file; see The Table concept...
void CopyFromVec(const VectorBase< Real > &v)
Copy data from another vector (must match own size).
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
void Read(std::istream &is, bool binary)
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
A class representing a vector.
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
void SetSpeakerVector(const Vector< BaseFloat > &v_s_in)
int32 SpkSpaceDim() const