35 using namespace kaldi;
37 using fst::SymbolTable;
42 "Generate lattices, reading log-likelihoods as matrices\n" 43 " (model is needed only for the integer mappings in its transition-model)\n" 44 "Usage: latgen-faster-mapped [options] trans-model-in (fst-in|fsts-rspecifier) loglikes-rspecifier" 45 " lattice-wspecifier [ words-wspecifier [alignments-wspecifier] ]\n";
48 bool allow_partial =
false;
52 std::string word_syms_filename;
54 po.Register(
"acoustic-scale", &acoustic_scale,
"Scaling factor for acoustic likelihoods");
56 po.Register(
"word-symbol-table", &word_syms_filename,
"Symbol table for words [for debug output]");
57 po.Register(
"allow-partial", &allow_partial,
"If true, produce output even if end state was not reached.");
61 if (po.NumArgs() < 4 || po.NumArgs() > 6) {
66 std::string model_in_filename = po.GetArg(1),
67 fst_in_str = po.GetArg(2),
68 feature_rspecifier = po.GetArg(3),
69 lattice_wspecifier = po.GetArg(4),
70 words_wspecifier = po.GetOptArg(5),
71 alignment_wspecifier = po.GetOptArg(6);
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 " 92 << word_syms_filename;
94 double tot_like = 0.0;
95 kaldi::int64 frame_count = 0;
96 int num_success = 0, num_fail = 0;
107 for (; !loglike_reader.Done(); loglike_reader.Next()) {
108 std::string utt = loglike_reader.Key();
110 loglike_reader.FreeCurrent();
111 if (loglikes.NumRows() == 0) {
112 KALDI_WARN <<
"Zero-length utterance: " << utt;
121 decoder, decodable, trans_model, word_syms, utt,
122 acoustic_scale, determinize, allow_partial, &alignment_writer,
123 &words_writer, &compact_lattice_writer, &lattice_writer,
126 frame_count += loglikes.NumRows();
135 for (; !fst_reader.Done(); fst_reader.Next()) {
136 std::string utt = fst_reader.Key();
137 if (!loglike_reader.HasKey(utt)) {
138 KALDI_WARN <<
"Not decoding utterance " << utt
139 <<
" because no loglikes available.";
145 KALDI_WARN <<
"Zero-length utterance: " << utt;
153 decoder, decodable, trans_model, word_syms, utt, acoustic_scale,
154 determinize, allow_partial, &alignment_writer, &words_writer,
155 &compact_lattice_writer, &lattice_writer, &like)) {
157 frame_count += loglikes.
NumRows();
163 double elapsed = timer.
Elapsed();
165 <<
"s: real-time factor assuming 100 frames/sec is " 166 << (elapsed*100.0/frame_count);
167 KALDI_LOG <<
"Done " << num_success <<
" utterances, failed for " 169 KALDI_LOG <<
"Overall log-likelihood per frame is " << (tot_like/frame_count) <<
" over " 170 << frame_count<<
" frames.";
173 if (num_success != 0)
return 0;
175 }
catch(
const std::exception &e) {
176 std::cerr << e.what();
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
bool Open(const std::string &wspecifier)
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 DecodeUtteranceLatticeFaster(LatticeFasterDecoderTpl< 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)
This function DecodeUtteranceLatticeFaster is used in several decoders, and we have moved it here...
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...
This is the "normal" lattice-generating decoder.
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
void Register(OptionsItf *opts)
double Elapsed() const
Returns time in seconds.