69 using namespace kaldi;
73 "Decode features using GMM-based model.\n" 74 "Usage: gmm-decode-faster [options] model-in fst-in features-rspecifier words-wspecifier [alignments-wspecifier [lattice-wspecifier]]\n" 75 "Note: lattices, if output, will just be linear sequences; use gmm-latgen-faster\n" 76 " if you want \"real\" lattices.\n";
78 bool allow_partial =
true;
81 std::string word_syms_filename;
84 po.Register(
"acoustic-scale", &acoustic_scale,
85 "Scaling factor for acoustic likelihoods");
86 po.Register(
"word-symbol-table", &word_syms_filename,
87 "Symbol table for words [for debug output]");
88 po.Register(
"allow-partial", &allow_partial,
89 "Produce output even when final state was not reached");
92 if (po.NumArgs() < 4 || po.NumArgs() > 6) {
97 std::string model_rxfilename = po.GetArg(1),
98 fst_rxfilename = po.GetArg(2),
99 feature_rspecifier = po.GetArg(3),
100 words_wspecifier = po.GetArg(4),
101 alignment_wspecifier = po.GetOptArg(5),
102 lattice_wspecifier = po.GetOptArg(6);
108 Input ki(model_rxfilename, &binary);
109 trans_model.
Read(ki.Stream(), binary);
110 am_gmm.
Read(ki.Stream(), binary);
119 fst::SymbolTable *word_syms = NULL;
120 if (word_syms_filename !=
"")
121 if (!(word_syms = fst::SymbolTable::ReadText(word_syms_filename)))
122 KALDI_ERR <<
"Could not read symbol table from file " 123 << word_syms_filename;
132 fst::Fst<fst::StdArc> *decode_fst =
ReadNetwork(fst_rxfilename);
135 kaldi::int64 frame_count = 0;
136 int num_success = 0, num_fail = 0;
141 for (; !feature_reader.Done(); feature_reader.Next()) {
142 std::string key = feature_reader.Key();
144 feature_reader.FreeCurrent();
145 if (features.NumRows() == 0) {
146 KALDI_WARN <<
"Zero-length utterance: " << key;
153 decoder.Decode(&gmm_decodable);
155 fst::VectorFst<LatticeArc> decoded;
157 if ( (allow_partial || decoder.ReachedFinal())
158 && decoder.GetBestPath(&decoded) ) {
159 if (!decoder.ReachedFinal())
160 KALDI_WARN <<
"Decoder did not reach end-state, " 161 <<
"outputting partial traceback since --allow-partial=true";
163 std::vector<int32> alignment;
164 std::vector<int32>
words;
166 frame_count += features.NumRows();
170 words_writer.Write(key, words);
171 if (alignment_writer.IsOpen())
172 alignment_writer.Write(key, alignment);
174 if (lattice_wspecifier !=
"") {
176 if (acoustic_scale != 0.0)
179 fst::VectorFst<CompactLatticeArc> clat;
181 clat_writer.Write(key, clat);
184 if (word_syms != NULL) {
185 std::cerr << key <<
' ';
186 for (
size_t i = 0;
i < words.size();
i++) {
187 std::string s = word_syms->Find(words[
i]);
189 KALDI_ERR <<
"Word-id " << words[
i] <<
" not in symbol table.";
190 std::cerr << s <<
' ';
196 KALDI_LOG <<
"Log-like per frame for utterance " << key <<
" is " 197 << (like / features.NumRows()) <<
" over " 198 << features.NumRows() <<
" frames.";
199 KALDI_VLOG(2) <<
"Cost for utterance " << key <<
" is " 203 KALDI_WARN <<
"Did not successfully decode utterance " << key
204 <<
", len = " << features.NumRows();
208 double elapsed = timer.
Elapsed();
209 KALDI_LOG <<
"Time taken [excluding initialization] "<< elapsed
210 <<
"s: real-time factor assuming 100 frames/sec is " 211 << (elapsed*100.0/frame_count);
212 KALDI_LOG <<
"Done " << num_success <<
" utterances, failed for " 214 KALDI_LOG <<
"Overall log-likelihood per frame is " << (tot_like/frame_count) <<
" over " 215 << frame_count<<
" frames.";
219 return (num_success != 0 ? 0 : 1);
220 }
catch(
const std::exception &e) {
221 std::cerr << e.what();
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
fst::Fst< fst::StdArc > * ReadNetwork(std::string filename)
A templated class for writing objects to an archive or script file; see The Table concept...
bool GetLinearSymbolSequence(const Fst< Arc > &fst, std::vector< I > *isymbols_out, std::vector< I > *osymbols_out, typename Arc::Weight *tot_weight_out)
GetLinearSymbolSequence gets the symbol sequence from a linear FST.
std::vector< std::vector< double > > AcousticLatticeScale(double acwt)
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
void ScaleLattice(const std::vector< std::vector< ScaleFloat > > &scale, MutableFst< ArcTpl< Weight > > *fst)
Scales the pairs of weights in LatticeWeight or CompactLatticeWeight by viewing the pair (a...
void Read(std::istream &is, bool binary)
void ConvertLattice(const ExpandedFst< ArcTpl< Weight > > &ifst, MutableFst< ArcTpl< CompactLatticeWeightTpl< Weight, Int > > > *ofst, bool invert)
Convert lattice from a normal FST to a CompactLattice FST.
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
void Register(OptionsItf *opts, bool full)
double Elapsed() const
Returns time in seconds.
void Read(std::istream &in_stream, bool binary)