145 using namespace kaldi;
147 using fst::SymbolTable;
148 using fst::VectorFst;
154 "Generate lattices using GMM-based model.\n" 155 "User supplies LM used to generate decoding graph, and desired LM;\n" 156 "this decoder applies the difference during decoding\n" 157 "Usage: gmm-latgen-biglm-faster [options] model-in (fst-in|fsts-rspecifier) " 158 "oldlm-fst-in newlm-fst-in features-rspecifier" 159 " lattice-wspecifier [ words-wspecifier [alignments-wspecifier] ]\n";
162 bool allow_partial =
false;
166 std::string word_syms_filename;
168 po.Register(
"acoustic-scale", &acoustic_scale,
"Scaling factor for acoustic likelihoods");
170 po.Register(
"word-symbol-table", &word_syms_filename,
"Symbol table for words [for debug output]");
171 po.Register(
"allow-partial", &allow_partial,
"If true, produce output even if end state was not reached.");
175 if (po.NumArgs() < 6 || po.NumArgs() > 8) {
180 std::string model_in_filename = po.GetArg(1),
181 fst_in_str = po.GetArg(2),
182 old_lm_fst_rxfilename = po.GetArg(3),
183 new_lm_fst_rxfilename = po.GetArg(4),
184 feature_rspecifier = po.GetArg(5),
185 lattice_wspecifier = po.GetArg(6),
186 words_wspecifier = po.GetOptArg(7),
187 alignment_wspecifier = po.GetOptArg(8);
193 Input ki(model_in_filename, &binary);
194 trans_model.
Read(ki.Stream(), binary);
195 am_gmm.
Read(ki.Stream(), binary);
214 if (! (determinize ? compact_lattice_writer.
Open(lattice_wspecifier)
215 : lattice_writer.
Open(lattice_wspecifier)))
216 KALDI_ERR <<
"Could not open table for writing lattices: " 217 << lattice_wspecifier;
223 fst::SymbolTable *word_syms = NULL;
224 if (word_syms_filename !=
"")
225 if (!(word_syms = fst::SymbolTable::ReadText(word_syms_filename)))
226 KALDI_ERR <<
"Could not read symbol table from file " 227 << word_syms_filename;
229 double tot_like = 0.0;
230 kaldi::int64 frame_count = 0;
231 int num_success = 0, num_fail = 0;
242 for (; !feature_reader.Done(); feature_reader.Next()) {
243 std::string utt = feature_reader.Key();
245 feature_reader.FreeCurrent();
246 if (features.NumRows() == 0) {
247 KALDI_WARN <<
"Zero-length utterance: " << utt;
258 utt, acoustic_scale, determinize, allow_partial,
259 &alignment_writer, &words_writer,
260 &compact_lattice_writer, &lattice_writer,
263 frame_count += features.NumRows();
272 for (; !fst_reader.Done(); fst_reader.Next()) {
273 std::string utt = fst_reader.Key();
274 if (!feature_reader.HasKey(utt)) {
275 KALDI_WARN <<
"Not decoding utterance " << utt
276 <<
" because no features available.";
282 KALDI_WARN <<
"Zero-length utterance: " << utt;
291 if (
DecodeUtterance(decoder, gmm_decodable, trans_model, word_syms, utt,
292 acoustic_scale, determinize, allow_partial,
293 &alignment_writer, &words_writer,
294 &compact_lattice_writer, &lattice_writer,
297 frame_count += features.
NumRows();
303 double elapsed = timer.
Elapsed();
305 <<
"s: real-time factor assuming 100 frames/sec is " 306 << (elapsed*100.0/frame_count);
307 KALDI_LOG <<
"Done " << num_success <<
" utterances, failed for " 309 KALDI_LOG <<
"Overall log-likelihood per frame is " << (tot_like/frame_count) <<
" over " 310 << frame_count<<
" frames.";
313 if (num_success != 0)
return 0;
315 }
catch(
const std::exception &e) {
316 std::cerr << e.what();
This class wraps an Fst, representing a language model, using the interface for "BackoffDeterministic...
bool DecodeUtterance(LatticeBiglmFasterDecoder &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 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...
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...
void Read(std::istream &is, bool binary)
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
This is as LatticeFasterDecoder, but does online composition between HCLG and the "difference languag...
void ApplyProbabilityScale(float scale, MutableFst< Arc > *fst)
ApplyProbabilityScale is applicable to FSTs in the log or tropical semiring.
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
void ReadFstKaldi(std::istream &is, bool binary, VectorFst< Arc > *fst)
VectorFst< StdArc > * CastOrConvertToVectorFst(Fst< StdArc > *fst)
void Register(OptionsItf *opts)
double Elapsed() const
Returns time in seconds.
void Read(std::istream &in_stream, bool binary)