33 int main(
int argc,
char *argv[]) {
35 using namespace kaldi;
38 using fst::SymbolTable;
43 "Generate lattices using neural net model.\n" 44 "Usage: nnet-latgen-faster [options] <nnet-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,
"Scaling factor for acoustic likelihoods");
55 po.
Register(
"word-symbol-table", &word_syms_filename,
"Symbol table for words [for debug output]");
56 po.
Register(
"allow-partial", &allow_partial,
"If true, produce output even if end state was not reached.");
65 std::string model_in_filename = po.
GetArg(1),
67 feature_rspecifier = po.
GetArg(3),
68 lattice_wspecifier = po.
GetArg(4),
76 Input ki(model_in_filename, &binary);
84 if (! (determinize ? compact_lattice_writer.
Open(lattice_wspecifier)
85 : lattice_writer.
Open(lattice_wspecifier)))
86 KALDI_ERR <<
"Could not open table for writing lattices: " 87 << lattice_wspecifier;
93 fst::SymbolTable *word_syms = NULL;
94 if (word_syms_filename !=
"")
95 if (!(word_syms = fst::SymbolTable::ReadText(word_syms_filename)))
96 KALDI_ERR <<
"Could not read symbol table from file " 97 << word_syms_filename;
100 double tot_like = 0.0;
101 kaldi::int64 frame_count = 0;
102 int num_success = 0, num_fail = 0;
114 for (; !feature_reader.
Done(); feature_reader.
Next()) {
115 std::string utt = feature_reader.
Key();
117 if (features.NumRows() == 0) {
118 KALDI_WARN <<
"Zero-length utterance: " << utt;
122 bool pad_input =
true;
130 decoder, nnet_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;
161 bool pad_input =
true;
169 decoder, nnet_decodable, trans_model, word_syms, utt,
170 acoustic_scale, determinize, allow_partial, &alignment_writer,
171 &words_writer, &compact_lattice_writer, &lattice_writer,
174 frame_count += features.
NumRows();
180 double elapsed = timer.
Elapsed();
182 <<
"s: real-time factor assuming 100 frames/sec is " 183 << (elapsed*100.0/frame_count);
184 KALDI_LOG <<
"Done " << num_success <<
" utterances, failed for " 186 KALDI_LOG <<
"Overall log-likelihood per frame is " << (tot_like/frame_count) <<
" over " 187 << frame_count<<
" frames.";
190 if (num_success != 0)
return 0;
192 }
catch(
const std::exception &e) {
193 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].
void Read(std::istream &is, bool binary)
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...
This class represents a matrix that's stored on the GPU if we have one, and in memory if not...
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[])
DecodableAmNnet is a decodable object that decodes with a neural net acoustic model of type AmNnet...
MatrixIndexT NumRows() const
Dimensions.
void Register(OptionsItf *opts)
double Elapsed() const
Returns time in seconds.
std::string GetOptArg(int param) const