35 int main(
int argc,
char *argv[]) {
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");
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),
85 Input ki(model_in_filename, &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();
115 if (features.NumRows() == 0) {
116 KALDI_WARN <<
"Zero-length utterance: " << utt;
123 decoder.
Decode(&gmm_decodable);
125 VectorFst<LatticeArc> decoded;
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)
void PrintUsage(bool print_command_line=false)
Prints the usage documentation [provided in the constructor].
bool ReachedFinal() const
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.
void Write(const std::string &key, const T &value) const
void Register(const std::string &name, bool *ptr, const std::string &doc)
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...
int Read(int argc, const char *const *argv)
Parses the command line options and fills the ParseOptions-registered variables.
int main(int argc, char *argv[])
std::string GetArg(int param) const
Returns one of the positional parameters; 1-based indexing for argc/argv compatibility.
int NumArgs() const
Number of positional parameters (c.f. argc-1).
bool Decode(DecodableInterface *decodable)
Decode this utterance.
Simplest possible decoder, included largely for didactic purposes and as a means to debug more highly...
bool GetBestPath(Lattice *fst_out, bool use_final_probs=true) const
double Elapsed() const
Returns time in seconds.
void Read(std::istream &in_stream, bool binary)
std::string GetOptArg(int param) const