109 using namespace kaldi;
111 using fst::SymbolTable;
113 using fst::VectorFst;
117 "Decode features using SGMM-based model. This version accepts the --num-threads\n" 118 "option but otherwise behaves identically to sgmm2-latgen-faster\n" 119 "Usage: sgmm2-latgen-faster-parallel [options] <model-in> (<fst-in>|<fsts-rspecifier>) " 120 "<features-rspecifier> <lattices-wspecifier> [<words-wspecifier> [<alignments-wspecifier>] ]\n";
123 bool allow_partial =
false;
125 string word_syms_filename, gselect_rspecifier, spkvecs_rspecifier,
133 po.Register(
"acoustic-scale", &acoustic_scale,
134 "Scaling factor for acoustic likelihoods");
135 po.Register(
"log-prune", &log_prune,
136 "Pruning beam used to reduce number of exp() evaluations.");
137 po.Register(
"word-symbol-table", &word_syms_filename,
138 "Symbol table for words [for debug output]");
139 po.Register(
"allow-partial", &allow_partial,
140 "Produce output even when final state was not reached");
141 po.Register(
"gselect", &gselect_rspecifier,
142 "rspecifier for precomputed per-frame Gaussian indices.");
143 po.Register(
"spk-vecs", &spkvecs_rspecifier,
144 "rspecifier for speaker vectors");
145 po.Register(
"utt2spk", &utt2spk_rspecifier,
146 "rspecifier for utterance to speaker map");
149 if (po.NumArgs() < 4 || po.NumArgs() > 6) {
154 if (gselect_rspecifier ==
"")
155 KALDI_ERR <<
"--gselect option is required.";
157 std::string model_in_filename = po.GetArg(1),
158 fst_in_str = po.GetArg(2),
159 feature_rspecifier = po.GetArg(3),
160 lattice_wspecifier = po.GetArg(4),
161 words_wspecifier = po.GetOptArg(5),
162 alignment_wspecifier = po.GetOptArg(6);
164 double tot_like = 0.0;
165 kaldi::int64 frame_count = 0;
166 int num_done = 0, num_err = 0;
168 Fst<StdArc> *decode_fst = NULL;
169 fst::SymbolTable *word_syms = NULL;
177 Input ki(model_in_filename, &binary);
178 trans_model.
Read(ki.Stream(), binary);
179 am_sgmm.
Read(ki.Stream(), binary);
186 if (! (determinize ? compact_lattice_writer.
Open(lattice_wspecifier)
187 : lattice_writer.
Open(lattice_wspecifier)))
188 KALDI_ERR <<
"Could not open table for writing lattices: " 189 << lattice_wspecifier;
194 if (word_syms_filename !=
"")
195 if (!(word_syms = fst::SymbolTable::ReadText(word_syms_filename)))
196 KALDI_ERR <<
"Could not read symbol table from file " 197 << word_syms_filename;
214 for (; !feature_reader.Done(); feature_reader.Next()) {
215 string utt = feature_reader.Key();
217 if (features.NumRows() == 0) {
218 KALDI_WARN <<
"Zero-length utterance: " << utt;
225 *decode_fst, decoder_opts);
228 features, gselect_reader, spkvecs_reader, word_syms,
229 utt, determinize, allow_partial,
230 &alignment_writer, &words_writer, &compact_lattice_writer,
231 &lattice_writer, decoder, &tot_like, &frame_count,
232 &num_done, &num_err, &sequencer);
238 for (; !fst_reader.Done(); fst_reader.Next()) {
239 std::string utt = fst_reader.Key();
240 if (!feature_reader.HasKey(utt)) {
241 KALDI_WARN <<
"Not decoding utterance " << utt
242 <<
" because no features available.";
248 KALDI_WARN <<
"Zero-length utterance: " << utt;
252 VectorFst<StdArc> *
fst = fst_reader.Value().Copy();
262 features, gselect_reader, spkvecs_reader, word_syms,
263 utt, determinize, allow_partial,
264 &alignment_writer, &words_writer, &compact_lattice_writer,
265 &lattice_writer, decoder, &tot_like, &frame_count,
266 &num_done, &num_err, &sequencer);
274 double elapsed = timer.
Elapsed();
276 KALDI_LOG <<
"Time taken [excluding initialization] "<< elapsed
277 <<
"s: real-time factor per thread assuming 100 frames/sec is " 278 << (sequencer_config.
num_threads * elapsed * 100.0 / frame_count);
279 KALDI_LOG <<
"Done " << num_done <<
" utterances, failed for " 281 KALDI_LOG <<
"Overall log-likelihood per frame = " << (tot_like/frame_count)
282 <<
" over " << frame_count <<
" frames.";
284 return (num_done != 0 ? 0 : 1);
285 }
catch(
const std::exception &e) {
286 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)
For an extended explanation of the framework of which grammar-fsts are a part, please see Support for...
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...
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...
void Read(std::istream &is, bool binary)
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
This is the "normal" lattice-generating decoder.
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
LatticeFasterDecoderTpl< fst::StdFst, decoder::StdToken > LatticeFasterDecoder
void Register(OptionsItf *opts)
double Elapsed() const
Returns time in seconds.
void Register(OptionsItf *opts)