34 int main(
int argc,
char *argv[]) {
36 using namespace kaldi;
38 using fst::SymbolTable;
43 "Generate lattices using GMM-based model.\n" 44 "Usage: gmm-latgen-faster [options] model-in (fst-in|fsts-rspecifier) features-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,
55 "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.");
68 std::string model_in_filename = po.
GetArg(1),
70 feature_rspecifier = po.
GetArg(3),
71 lattice_wspecifier = po.
GetArg(4),
79 Input ki(model_in_filename, &binary);
87 if (! (determinize ? compact_lattice_writer.
Open(lattice_wspecifier)
88 : lattice_writer.
Open(lattice_wspecifier)))
89 KALDI_ERR <<
"Could not open table for writing lattices: " 90 << lattice_wspecifier;
96 fst::SymbolTable *word_syms = NULL;
97 if (word_syms_filename !=
"")
98 if (!(word_syms = fst::SymbolTable::ReadText(word_syms_filename)))
99 KALDI_ERR <<
"Could not read symbol table from file " 100 << word_syms_filename;
102 double tot_like = 0.0;
103 kaldi::int64 frame_count = 0;
104 int num_done = 0, num_err = 0;
115 for (; !feature_reader.
Done(); feature_reader.
Next()) {
116 std::string utt = feature_reader.
Key();
119 if (features.NumRows() == 0) {
120 KALDI_WARN <<
"Zero-length utterance: " << utt;
130 decoder, gmm_decodable, trans_model, word_syms, utt,
131 acoustic_scale, determinize, allow_partial, &alignment_writer,
132 &words_writer, &compact_lattice_writer, &lattice_writer,
135 frame_count += features.NumRows();
144 for (; !fst_reader.
Done(); fst_reader.
Next()) {
145 std::string utt = fst_reader.
Key();
146 if (!feature_reader.
HasKey(utt)) {
147 KALDI_WARN <<
"Not decoding utterance " << utt
148 <<
" because no features available.";
154 KALDI_WARN <<
"Zero-length utterance: " << utt;
164 decoder, gmm_decodable, trans_model, word_syms, utt,
165 acoustic_scale, determinize, allow_partial, &alignment_writer,
166 &words_writer, &compact_lattice_writer, &lattice_writer,
169 frame_count += features.
NumRows();
175 double elapsed = timer.
Elapsed();
177 <<
"s: real-time factor assuming 100 frames/sec is " 178 << (elapsed*100.0/frame_count);
179 KALDI_LOG <<
"Done " << num_done <<
" utterances, failed for " 181 KALDI_LOG <<
"Overall log-likelihood per frame is " << (tot_like/frame_count) <<
" over " 182 << frame_count <<
" frames.";
185 if (num_done != 0)
return 0;
187 }
catch(
const std::exception &e) {
188 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 PrintUsage(bool print_command_line=false)
Prints the usage documentation [provided in the constructor].
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...
void Register(const std::string &name, bool *ptr, const std::string &doc)
RspecifierType ClassifyRspecifier(const std::string &rspecifier, std::string *rxfilename, RspecifierOptions *opts)
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...
const T & Value(const std::string &key)
void Read(std::istream &is, bool binary)
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).
int main(int argc, char *argv[])
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
void Register(OptionsItf *opts)
double Elapsed() const
Returns time in seconds.
void Read(std::istream &in_stream, bool binary)
std::string GetOptArg(int param) const