42 double acoustic_scale,
46 const fst::SymbolTable *word_syms,
47 const std::string &utt,
58 if (spkvecs_reader.
IsOpen()) {
59 if (spkvecs_reader.
HasKey(utt)) {
63 KALDI_WARN <<
"Cannot find speaker vector for " << utt <<
", not decoding this utterance";
68 if (!gselect_reader.
HasKey(utt) ||
69 gselect_reader.
Value(utt).size() != features.
NumRows()) {
70 KALDI_WARN <<
"No Gaussian-selection info available for utterance " 71 << utt <<
" (or wrong size)";
74 const std::vector<std::vector<int32> > &gselect =
75 gselect_reader.
Value(utt);
78 log_prune, acoustic_scale, &spk_vars);
81 decoder, sgmm_decodable, trans_model, word_syms, utt, acoustic_scale,
82 determinize, allow_partial, alignments_writer, words_writer,
83 compact_lattice_writer, lattice_writer, like_ptr);
88 int main(
int argc,
char *argv[]) {
90 using namespace kaldi;
92 using fst::SymbolTable;
97 "Decode features using SGMM-based model.\n" 98 "Usage: sgmm2-latgen-faster [options] <model-in> (<fst-in>|<fsts-rspecifier>) " 99 "<features-rspecifier> <lattices-wspecifier> [<words-wspecifier> [<alignments-wspecifier>] ]\n";
102 bool allow_partial =
false;
104 string word_syms_filename, gselect_rspecifier, spkvecs_rspecifier,
110 po.
Register(
"acoustic-scale", &acoustic_scale,
111 "Scaling factor for acoustic likelihoods");
112 po.
Register(
"log-prune", &log_prune,
113 "Pruning beam used to reduce number of exp() evaluations.");
114 po.
Register(
"word-symbol-table", &word_syms_filename,
115 "Symbol table for words [for debug output]");
116 po.
Register(
"allow-partial", &allow_partial,
117 "Produce output even when final state was not reached");
118 po.
Register(
"gselect", &gselect_rspecifier,
119 "rspecifier for precomputed per-frame Gaussian indices.");
120 po.
Register(
"spk-vecs", &spkvecs_rspecifier,
121 "rspecifier for speaker vectors");
122 po.
Register(
"utt2spk", &utt2spk_rspecifier,
123 "rspecifier for utterance to speaker map");
131 if (gselect_rspecifier ==
"")
132 KALDI_ERR <<
"--gselect option is required.";
134 std::string model_in_filename = po.
GetArg(1),
135 fst_in_str = po.
GetArg(2),
136 feature_rspecifier = po.
GetArg(3),
137 lattice_wspecifier = po.
GetArg(4),
145 Input ki(model_in_filename, &binary);
153 if (! (determinize ? compact_lattice_writer.
Open(lattice_wspecifier)
154 : lattice_writer.
Open(lattice_wspecifier)))
155 KALDI_ERR <<
"Could not open table for writing lattices: " 156 << lattice_wspecifier;
162 fst::SymbolTable *word_syms = NULL;
163 if (word_syms_filename !=
"")
164 if (!(word_syms = fst::SymbolTable::ReadText(word_syms_filename)))
165 KALDI_ERR <<
"Could not read symbol table from file " 166 << word_syms_filename;
173 kaldi::int64 frame_count = 0;
174 int num_success = 0, num_err = 0;
191 const std::vector<std::vector<int32> > empty_gselect;
193 for (; !feature_reader.
Done(); feature_reader.
Next()) {
194 string utt = feature_reader.
Key();
196 if (features.NumRows() == 0) {
197 KALDI_WARN <<
"Zero-length utterance: " << utt;
202 if (
ProcessUtterance(decoder, am_sgmm, trans_model, log_prune, acoustic_scale,
203 features, gselect_reader, spkvecs_reader, word_syms,
204 utt, determinize, allow_partial,
205 &alignment_writer, &words_writer, &compact_lattice_writer,
206 &lattice_writer, &like)) {
208 frame_count += features.NumRows();
209 KALDI_LOG <<
"Log-like per frame for utterance " << utt <<
" is " 210 << (like / features.NumRows()) <<
" over " 211 << features.NumRows() <<
" frames.";
213 }
else { num_err++; }
220 for (; !fst_reader.
Done(); fst_reader.
Next()) {
221 std::string utt = fst_reader.
Key();
222 if (!feature_reader.
HasKey(utt)) {
223 KALDI_WARN <<
"Not decoding utterance " << utt
224 <<
" because no features available.";
230 KALDI_WARN <<
"Zero-length utterance: " << utt;
237 if (
ProcessUtterance(decoder, am_sgmm, trans_model, log_prune, acoustic_scale,
238 features, gselect_reader, spkvecs_reader, word_syms,
239 utt, determinize, allow_partial,
240 &alignment_writer, &words_writer, &compact_lattice_writer,
241 &lattice_writer, &like)) {
243 frame_count += features.
NumRows();
244 KALDI_LOG <<
"Log-like per frame for utterance " << utt <<
" is " 245 << (like / features.
NumRows()) <<
" over " 246 << features.
NumRows() <<
" frames.";
248 }
else { num_err++; }
251 double elapsed = timer.
Elapsed();
252 KALDI_LOG <<
"Time taken [excluding initialization] "<< elapsed
253 <<
"s: real-time factor assuming 100 frames/sec is " 254 << (elapsed*100.0/frame_count);
255 KALDI_LOG <<
"Done " << num_success <<
" utterances, failed for " 257 KALDI_LOG <<
"Overall log-likelihood per frame = " << (tot_like/frame_count)
258 <<
" over " << frame_count <<
" frames.";
261 return (num_success != 0 ? 0 : 1);
262 }
catch(
const std::exception &e) {
263 std::cerr << e.what();
void ProcessUtterance(const AmSgmm2 &am_sgmm, const TransitionModel &trans_model, double log_prune, double acoustic_scale, const Matrix< BaseFloat > &features, RandomAccessInt32VectorVectorReader &gselect_reader, RandomAccessBaseFloatVectorReaderMapped &spkvecs_reader, const fst::SymbolTable *word_syms, const std::string &utt, bool determinize, bool allow_partial, Int32VectorWriter *alignments_writer, Int32VectorWriter *words_writer, CompactLatticeWriter *compact_lattice_writer, LatticeWriter *lattice_writer, LatticeFasterDecoder *decoder, double *like_sum, int64 *frame_sum, int32 *num_done, int32 *num_err, TaskSequencer< DecodeUtteranceLatticeFasterClass > *sequencer)
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Class for definition of the subspace Gmm acoustic model.
bool Open(const std::string &wspecifier)
Fst< StdArc > * ReadFstKaldiGeneric(std::string rxfilename, bool throw_on_err)
void PrintUsage(bool print_command_line=false)
Prints the usage documentation [provided in the constructor].
This class is for when you are reading something in random access, but it may actually be stored per-...
void Read(std::istream &is, bool binary)
A templated class for writing objects to an archive or script file; see The Table concept...
bool DecodeUtteranceLatticeFaster(LatticeFasterDecoderTpl< FST > &decoder, DecodableInterface &decodable, const TransitionModel &trans_model, const fst::SymbolTable *word_syms, std::string utt, double acoustic_scale, bool determinize, bool allow_partial, Int32VectorWriter *alignment_writer, Int32VectorWriter *words_writer, CompactLatticeWriter *compact_lattice_writer, LatticeWriter *lattice_writer, double *like_ptr)
This function DecodeUtteranceLatticeFaster is used in several decoders, and we have moved it here...
void ComputePerSpkDerivedVars(Sgmm2PerSpkDerivedVars *vars) const
Computes the per-speaker derived vars; assumes vars->v_s is already set up.
void Register(const std::string &name, bool *ptr, const std::string &doc)
RspecifierType ClassifyRspecifier(const std::string &rspecifier, std::string *rxfilename, RspecifierOptions *opts)
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...
const T & Value(const std::string &key)
void Read(std::istream &is, bool binary)
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.
bool HasKey(const std::string &key)
This is the "normal" lattice-generating decoder.
int NumArgs() const
Number of positional parameters (c.f. argc-1).
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
const T & Value(const std::string &key)
void SetSpeakerVector(const Vector< BaseFloat > &v_s_in)
void Register(OptionsItf *opts)
double Elapsed() const
Returns time in seconds.
std::string GetOptArg(int param) const
int main(int argc, char *argv[])