32 int main(
int argc,
char *argv[]) {
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]");
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),
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;
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)
void PrintUsage(bool print_command_line=false)
Prints the usage documentation [provided in the constructor].
void Decode(DecodableInterface *decodable)
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)
void ReadKaldiObject(const std::string &filename, Matrix< float > *m)
int main(int argc, char *argv[])
bool GetBestPath(fst::MutableFst< LatticeArc > *fst_out, bool use_final_probs=true)
GetBestPath gets the decoding traceback.
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...
int Read(int argc, const char *const *argv)
Parses the command line options and fills the ParseOptions-registered variables.
std::string GetArg(int param) const
Returns one of the positional parameters; 1-based indexing for argc/argv compatibility.
void Register(OptionsItf *opts, bool full)
int NumArgs() const
Number of positional parameters (c.f. argc-1).
double Elapsed() const
Returns time in seconds.
bool ReachedFinal() const
Returns true if a final state was active on the last frame.
std::string GetOptArg(int param) const