35 int main(
int argc,
char *argv[]) {
37 using namespace kaldi;
39 using fst::SymbolTable;
44 "Generate lattices using GMM-based model.\n" 45 "Usage: gmm-latgen-simple [options] model-in fst-in features-rspecifier" 46 " lattice-wspecifier [ words-wspecifier [alignments-wspecifier] ]\n";
49 bool allow_partial =
false;
53 std::string word_syms_filename;
55 po.
Register(
"acoustic-scale", &acoustic_scale,
"Scaling factor for acoustic likelihoods");
57 po.
Register(
"word-symbol-table", &word_syms_filename,
"Symbol table for words [for debug output]");
58 po.
Register(
"allow-partial", &allow_partial,
"If true, produce output even if end state was not reached.");
67 std::string model_in_filename = po.
GetArg(1),
68 fst_in_filename = po.
GetArg(2),
69 feature_rspecifier = po.
GetArg(3),
70 lattice_wspecifier = po.
GetArg(4),
78 Input ki(model_in_filename, &binary);
88 if (! (determinize ? compact_lattice_writer.
Open(lattice_wspecifier)
89 : lattice_writer.
Open(lattice_wspecifier)))
90 KALDI_ERR <<
"Could not open table for writing lattices: " 91 << lattice_wspecifier;
97 fst::SymbolTable *word_syms = NULL;
98 if (word_syms_filename !=
"")
99 if (!(word_syms = fst::SymbolTable::ReadText(word_syms_filename)))
100 KALDI_ERR <<
"Could not read symbol table from file " 101 << word_syms_filename;
106 kaldi::int64 frame_count = 0;
107 int num_success = 0, num_fail = 0;
110 for (; !feature_reader.
Done(); feature_reader.
Next()) {
111 std::string utt = feature_reader.
Key();
114 if (features.NumRows() == 0) {
115 KALDI_WARN <<
"Zero-length utterance: " << utt;
125 decoder, gmm_decodable, trans_model, word_syms, utt,
126 acoustic_scale, determinize, allow_partial, &alignment_writer,
127 &words_writer, &compact_lattice_writer, &lattice_writer, &like)) {
129 frame_count += features.NumRows();
134 double elapsed = timer.
Elapsed();
136 <<
"s: real-time factor assuming 100 frames/sec is " 137 << (elapsed*100.0/frame_count);
138 KALDI_LOG <<
"Done " << num_success <<
" utterances, failed for " 140 KALDI_LOG <<
"Overall log-likelihood per frame is " << (tot_like/frame_count) <<
" over " 141 << frame_count<<
" frames.";
145 if (num_success != 0)
return 0;
147 }
catch(
const std::exception &e) {
148 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...
void Register(OptionsItf *opts)
void Register(const std::string &name, bool *ptr, const std::string &doc)
int main(int argc, char *argv[])
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
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.
Simplest possible decoder, included largely for didactic purposes and as a means to debug more highly...
bool DecodeUtteranceLatticeSimple(LatticeSimpleDecoder &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)
int NumArgs() const
Number of positional parameters (c.f. argc-1).
double Elapsed() const
Returns time in seconds.
void Read(std::istream &in_stream, bool binary)
std::string GetOptArg(int param) const