34 int main(
int argc,
char *argv[]) {
36 using namespace kaldi;
38 using fst::SymbolTable;
43 "Generate lattices, reading log-likelihoods as matrices, using multiple decoding threads\n" 44 " (model is needed only for the integer mappings in its transition-model)\n" 45 "Usage: latgen-faster-mapped-parallel [options] trans-model-in (fst-in|fsts-rspecifier) loglikes-rspecifier" 46 " lattice-wspecifier [ words-wspecifier [alignments-wspecifier] ]\n";
49 bool allow_partial =
false;
54 std::string word_syms_filename;
58 po.
Register(
"acoustic-scale", &acoustic_scale,
"Scaling factor for acoustic likelihoods");
60 po.
Register(
"word-symbol-table", &word_syms_filename,
"Symbol table for words [for debug output]");
61 po.
Register(
"allow-partial", &allow_partial,
"If true, produce output even if end state was not reached.");
70 std::string model_in_filename = po.
GetArg(1),
72 feature_rspecifier = po.
GetArg(3),
73 lattice_wspecifier = po.
GetArg(4),
83 if (! (determinize ? compact_lattice_writer.
Open(lattice_wspecifier)
84 : lattice_writer.
Open(lattice_wspecifier)))
85 KALDI_ERR <<
"Could not open table for writing lattices: " 86 << lattice_wspecifier;
92 fst::SymbolTable *word_syms = NULL;
93 if (word_syms_filename !=
"")
94 if (!(word_syms = fst::SymbolTable::ReadText(word_syms_filename)))
95 KALDI_ERR <<
"Could not read symbol table from file " 96 << word_syms_filename;
98 double tot_like = 0.0;
99 kaldi::int64 frame_count = 0;
100 int num_success = 0, num_fail = 0;
101 Fst<StdArc> *decode_fst = NULL;
111 for (; !loglike_reader.
Done(); loglike_reader.
Next()) {
112 std::string utt = loglike_reader.
Key();
116 if (loglikes->
NumRows() == 0) {
117 KALDI_WARN <<
"Zero-length utterance: " << utt;
129 decoder, decodable, trans_model, word_syms, utt,
130 acoustic_scale, determinize, allow_partial, &alignment_writer,
131 &words_writer, &compact_lattice_writer, &lattice_writer,
132 &tot_like, &frame_count, &num_success, &num_fail, NULL);
141 for (; !fst_reader.
Done(); fst_reader.
Next()) {
142 std::string utt = fst_reader.
Key();
143 if (!loglike_reader.
HasKey(utt)) {
144 KALDI_WARN <<
"Not decoding utterance " << utt
145 <<
" because no loglikes available.";
151 if (loglikes->
NumRows() == 0) {
152 KALDI_WARN <<
"Zero-length utterance: " << utt;
157 fst::VectorFst<StdArc> *
fst =
158 new fst::VectorFst<StdArc>(fst_reader.
Value());
165 decoder, decodable, trans_model, word_syms, utt, acoustic_scale,
166 determinize, allow_partial, &alignment_writer, &words_writer,
167 &compact_lattice_writer, &lattice_writer, &tot_like,
168 &frame_count, &num_success, &num_fail, NULL);
177 double elapsed = timer.
Elapsed();
180 <<
"s: real-time factor per thread assuming 100 frames/sec is " 181 << (sequencer_config.
num_threads*elapsed*100.0/frame_count);
182 KALDI_LOG <<
"Done " << num_success <<
" utterances, failed for " 184 KALDI_LOG <<
"Overall log-likelihood per frame is " << (tot_like/frame_count) <<
" over " 185 << frame_count<<
" frames.";
188 if (num_success != 0)
return 0;
190 }
catch(
const std::exception &e) {
191 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)
void Run(C *c)
This function takes ownership of the pointer "c", and will delete it in the same sequence as Run was ...
For an extended explanation of the framework of which grammar-fsts are a part, please see Support for...
void PrintUsage(bool print_command_line=false)
Prints the usage documentation [provided in the constructor].
int main(int argc, char *argv[])
A templated class for writing objects to an archive or script file; see The Table concept...
void Register(const std::string &name, bool *ptr, const std::string &doc)
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...
This class basically does the same job as the function DecodeUtteranceLatticeFaster, but in a way that allows us to build a multi-threaded command line program more easily.
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
const T & Value(const std::string &key)
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.
bool HasKey(const std::string &key)
This is the "normal" lattice-generating decoder.
int NumArgs() const
Number of positional parameters (c.f. argc-1).
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
LatticeFasterDecoderTpl< fst::StdFst, decoder::StdToken > LatticeFasterDecoder
void Register(OptionsItf *opts)
double Elapsed() const
Returns time in seconds.
std::string GetOptArg(int param) const
void Register(OptionsItf *opts)