34 using namespace kaldi;
36 using fst::SymbolTable;
42 "Decode, reading log-likelihoods as matrices\n" 43 " (model is needed only for the integer mappings in its transition-model)\n" 44 "Usage: decode-faster-mapped [options] <model-in> <fst-in> " 45 "<loglikes-rspecifier> <words-wspecifier> [<alignments-wspecifier>]\n";
49 bool allow_partial =
true;
50 std::string word_syms_filename;
53 po.Register(
"binary", &binary,
"Write output in binary mode");
54 po.Register(
"acoustic-scale", &acoustic_scale,
"Scaling factor for acoustic likelihoods");
55 po.Register(
"allow-partial", &allow_partial,
"Produce output even when final state was not reached");
56 po.Register(
"word-symbol-table", &word_syms_filename,
"Symbol table for words [for debug output]");
60 if (po.NumArgs() < 4 || po.NumArgs() > 5) {
65 std::string model_in_filename = po.GetArg(1),
66 fst_in_filename = po.GetArg(2),
67 loglikes_rspecifier = po.GetArg(3),
68 words_wspecifier = po.GetArg(4),
69 alignment_wspecifier = po.GetOptArg(5);
78 fst::SymbolTable *word_syms = NULL;
79 if (word_syms_filename !=
"") {
80 word_syms = fst::SymbolTable::ReadText(word_syms_filename);
82 KALDI_ERR <<
"Could not read symbol table from file "<<word_syms_filename;
95 kaldi::int64 frame_count = 0;
96 int num_success = 0, num_fail = 0;
101 for (; !loglikes_reader.Done(); loglikes_reader.Next()) {
102 std::string key = loglikes_reader.Key();
105 if (loglikes.NumRows() == 0) {
106 KALDI_WARN <<
"Zero-length utterance: " << key;
112 decoder.Decode(&decodable);
114 VectorFst<LatticeArc> decoded;
116 if ( (allow_partial || decoder.ReachedFinal())
117 && decoder.GetBestPath(&decoded) ) {
119 if (!decoder.ReachedFinal())
120 KALDI_WARN <<
"Decoder did not reach end-state, outputting partial traceback.";
122 std::vector<int32> alignment;
123 std::vector<int32>
words;
125 frame_count += loglikes.NumRows();
129 words_writer.Write(key, words);
130 if (alignment_writer.IsOpen())
131 alignment_writer.Write(key, alignment);
132 if (word_syms != NULL) {
133 std::cerr << key <<
' ';
134 for (
size_t i = 0;
i < words.size();
i++) {
135 std::string s = word_syms->Find(words[
i]);
137 KALDI_ERR <<
"Word-id " << words[
i] <<
" not in symbol table.";
138 std::cerr << s <<
' ';
144 KALDI_LOG <<
"Log-like per frame for utterance " << key <<
" is " 145 << (like / loglikes.NumRows()) <<
" over " 146 << loglikes.NumRows() <<
" frames.";
150 KALDI_WARN <<
"Did not successfully decode utterance " << key
151 <<
", len = " << loglikes.NumRows();
155 double elapsed = timer.
Elapsed();
156 KALDI_LOG <<
"Time taken [excluding initialization] "<< elapsed
157 <<
"s: real-time factor assuming 100 frames/sec is " 158 << (elapsed*100.0/frame_count);
159 KALDI_LOG <<
"Done " << num_success <<
" utterances, failed for " 161 KALDI_LOG <<
"Overall log-likelihood per frame is " << (tot_like/frame_count)
162 <<
" over " << frame_count <<
" frames.";
166 if (num_success != 0)
return 0;
168 }
catch(
const std::exception &e) {
169 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.
void ReadKaldiObject(const std::string &filename, Matrix< float > *m)
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
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.