37 using namespace kaldi;
39 using fst::SymbolTable;
46 "Decode features using GMM-based model.\n" 47 "Viterbi decoding, Only produces linear sequence; any lattice\n" 48 "produced is linear\n" 50 "Usage: gmm-decode-simple [options] <model-in> <fst-in> " 51 "<features-rspecifier> <words-wspecifier> [<alignments-wspecifier>] " 52 "[<lattice-wspecifier>]";
55 bool allow_partial =
true;
58 std::string word_syms_filename;
60 po.Register(
"beam", &beam,
"Decoding log-likelihood beam");
61 po.Register(
"acoustic-scale", &acoustic_scale,
62 "Scaling factor for acoustic likelihoods");
63 po.Register(
"word-symbol-table", &word_syms_filename,
64 "Symbol table for words [for debug output]");
65 po.Register(
"allow-partial", &allow_partial,
66 "Produce output even when final state was not reached");
69 if (po.NumArgs() < 4 || po.NumArgs() > 6) {
74 std::string model_in_filename = po.GetArg(1),
75 fst_in_filename = po.GetArg(2),
76 feature_rspecifier = po.GetArg(3),
77 words_wspecifier = po.GetArg(4),
78 alignment_wspecifier = po.GetOptArg(5),
79 lattice_wspecifier = po.GetOptArg(6);
85 Input ki(model_in_filename, &binary);
86 trans_model.
Read(ki.Stream(), binary);
87 am_gmm.
Read(ki.Stream(), binary);
98 fst::SymbolTable *word_syms = NULL;
99 if (word_syms_filename !=
"")
100 if (!(word_syms = fst::SymbolTable::ReadText(word_syms_filename)))
101 KALDI_ERR <<
"Could not read symbol table from file " 102 << word_syms_filename;
107 kaldi::int64 frame_count = 0;
108 int num_success = 0, num_fail = 0;
111 for (; !feature_reader.Done(); feature_reader.Next()) {
112 std::string utt = feature_reader.Key();
114 feature_reader.FreeCurrent();
115 if (features.NumRows() == 0) {
116 KALDI_WARN <<
"Zero-length utterance: " << utt;
123 decoder.Decode(&gmm_decodable);
125 VectorFst<LatticeArc> decoded;
127 if ( (allow_partial || decoder.ReachedFinal())
128 && decoder.GetBestPath(&decoded) ) {
129 if (!decoder.ReachedFinal())
130 KALDI_WARN <<
"Decoder did not reach end-state, " 131 <<
"outputting partial traceback since --allow-partial=true";
134 std::vector<int32> alignment;
135 std::vector<int32>
words;
137 frame_count += features.NumRows();
141 words_writer.Write(utt, words);
142 if (alignment_wspecifier !=
"")
143 alignment_writer.Write(utt, alignment);
144 if (lattice_wspecifier !=
"") {
146 if (acoustic_scale != 0.0)
149 fst::VectorFst<CompactLatticeArc> clat;
151 clat_writer.Write(utt, clat);
153 if (word_syms != NULL) {
154 std::cerr << utt <<
' ';
155 for (
size_t i = 0;
i < words.size();
i++) {
156 std::string s = word_syms->Find(words[
i]);
158 KALDI_ERR <<
"Word-id " << words[
i] <<
" not in symbol table.";
159 std::cerr << s <<
' ';
165 KALDI_LOG <<
"Log-like per frame for utterance " << utt <<
" is " 166 << (like / features.NumRows()) <<
" over " 167 << features.NumRows() <<
" frames.";
170 KALDI_WARN <<
"Did not successfully decode utterance " << utt
171 <<
", len = " << features.NumRows();
175 double elapsed = timer.
Elapsed();
177 <<
"s: real-time factor assuming 100 frames/sec is " 178 << (elapsed*100.0/frame_count);
179 KALDI_LOG <<
"Done " << num_success <<
" utterances, failed for " 181 KALDI_LOG <<
"Overall log-likelihood per frame is " << (tot_like/frame_count) <<
" over " 182 << frame_count<<
" frames.";
186 if (num_success != 0)
return 0;
188 }
catch(
const std::exception &e) {
189 std::cerr << e.what();
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Fst< StdArc > * ReadFstKaldiGeneric(std::string rxfilename, bool throw_on_err)
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)
double ConvertToCost(const LatticeWeightTpl< Float > &w)
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...
Simplest possible decoder, included largely for didactic purposes and as a means to debug more highly...
double Elapsed() const
Returns time in seconds.
void Read(std::istream &in_stream, bool binary)