31 using namespace kaldi;
33 using fst::SymbolTable;
38 "Generate lattices, reading log-likelihoods as matrices\n" 39 " (model is needed only for the integer mappings in its transition-model)\n" 40 "The lattice determinization algorithm here can operate\n" 42 "Usage: latgen-incremental-mapped [options] trans-model-in " 43 "(fst-in|fsts-rspecifier) loglikes-rspecifier" 44 " lattice-wspecifier [ words-wspecifier [alignments-wspecifier] ]\n";
47 bool allow_partial =
false;
51 std::string word_syms_filename;
53 po.Register(
"acoustic-scale", &acoustic_scale,
54 "Scaling factor for acoustic likelihoods");
56 po.Register(
"word-symbol-table", &word_syms_filename,
57 "Symbol table for words [for debug output]");
58 po.Register(
"allow-partial", &allow_partial,
59 "If true, produce output even if end state was not reached.");
63 if (po.NumArgs() < 4 || po.NumArgs() > 6) {
68 std::string model_in_filename = po.GetArg(1), fst_in_str = po.GetArg(2),
69 feature_rspecifier = po.GetArg(3), lattice_wspecifier = po.GetArg(4),
70 words_wspecifier = po.GetOptArg(5),
71 alignment_wspecifier = po.GetOptArg(6);
76 bool determinize =
true;
79 if (!(determinize ? compact_lattice_writer.
Open(lattice_wspecifier)
80 : lattice_writer.
Open(lattice_wspecifier)))
81 KALDI_ERR <<
"Could not open table for writing lattices: " 82 << lattice_wspecifier;
88 fst::SymbolTable *word_syms = NULL;
89 if (word_syms_filename !=
"")
90 if (!(word_syms = fst::SymbolTable::ReadText(word_syms_filename)))
91 KALDI_ERR <<
"Could not read symbol table from file " << word_syms_filename;
93 double tot_like = 0.0;
94 kaldi::int64 frame_count = 0;
95 int num_success = 0, num_fail = 0;
106 for (; !loglike_reader.Done(); loglike_reader.Next()) {
107 std::string utt = loglike_reader.Key();
109 loglike_reader.FreeCurrent();
110 if (loglikes.NumRows() == 0) {
111 KALDI_WARN <<
"Zero-length utterance: " << utt;
121 decoder, decodable, trans_model, word_syms, utt, acoustic_scale,
122 determinize, allow_partial, &alignment_writer, &words_writer,
123 &compact_lattice_writer, &lattice_writer, &like)) {
125 frame_count += loglikes.NumRows();
136 for (; !fst_reader.Done(); fst_reader.Next()) {
137 std::string utt = fst_reader.Key();
138 if (!loglike_reader.HasKey(utt)) {
139 KALDI_WARN <<
"Not decoding utterance " << utt
140 <<
" because no loglikes available.";
146 KALDI_WARN <<
"Zero-length utterance: " << utt;
154 decoder, decodable, trans_model, word_syms, utt, acoustic_scale,
155 determinize, allow_partial, &alignment_writer, &words_writer,
156 &compact_lattice_writer, &lattice_writer, &like)) {
158 frame_count += loglikes.
NumRows();
166 double elapsed = timer.
Elapsed();
168 <<
"s: real-time factor assuming 100 frames/sec is " 169 << (elapsed * 100.0 / frame_count);
170 KALDI_LOG <<
"Done " << num_success <<
" utterances, failed for " << num_fail;
171 KALDI_LOG <<
"Overall log-likelihood per frame is " << (tot_like / frame_count)
172 <<
" over " << frame_count <<
" frames.";
175 if (num_success != 0)
179 }
catch (
const std::exception &e) {
180 std::cerr << e.what();
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
bool DecodeUtteranceLatticeIncremental(LatticeIncrementalDecoderTpl< FST > &decoder, DecodableInterface &decodable, const TransitionModel &trans_model, const fst::SymbolTable *word_syms, std::string utt, double acoustic_scale, bool determinize, bool allow_partial, Int32VectorWriter *alignment_writer, Int32VectorWriter *words_writer, CompactLatticeWriter *compact_lattice_writer, LatticeWriter *lattice_writer, double *like_ptr)
TODO.
bool Open(const std::string &wspecifier)
Fst< StdArc > * ReadFstKaldiGeneric(std::string rxfilename, bool throw_on_err)
This is an extention to the "normal" lattice-generating decoder.
A templated class for writing objects to an archive or script file; see The Table concept...
RspecifierType ClassifyRspecifier(const std::string &rspecifier, std::string *rxfilename, RspecifierOptions *opts)
void ReadKaldiObject(const std::string &filename, Matrix< float > *m)
Allows random access to a collection of objects in an archive or script file; see The Table concept...
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...
The normal decoder, lattice-faster-decoder.h, sometimes has an issue when doing real-time application...
void Register(OptionsItf *opts)
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
double Elapsed() const
Returns time in seconds.