34 fst::Fst<fst::StdArc> *
ReadNetwork(std::string filename) {
37 if (!ki.Stream().good())
KALDI_ERR <<
"Could not open decoding-graph FST " 40 if (!hdr.Read(ki.Stream(),
"<unknown>")) {
41 KALDI_ERR <<
"Reading FST: error reading FST header.";
43 if (hdr.ArcType() != fst::StdArc::Type()) {
44 KALDI_ERR <<
"FST with arc type " << hdr.ArcType() <<
" not supported.";
46 fst::FstReadOptions ropts(
"<unspecified>", &hdr);
48 fst::Fst<fst::StdArc> *decode_fst = NULL;
50 if (hdr.FstType() ==
"vector") {
51 decode_fst = fst::VectorFst<fst::StdArc>::Read(ki.Stream(), ropts);
52 }
else if (hdr.FstType() ==
"const") {
53 decode_fst = fst::ConstFst<fst::StdArc>::Read(ki.Stream(), ropts);
55 KALDI_ERR <<
"Reading FST: unsupported FST type: " << hdr.FstType();
57 if (decode_fst == NULL) {
58 KALDI_ERR <<
"Error reading FST (after reading header).";
67 int main(
int argc,
char *argv[]) {
69 using namespace kaldi;
73 "Decode features using GMM-based model.\n" 74 "Usage: gmm-decode-faster [options] model-in fst-in features-rspecifier words-wspecifier [alignments-wspecifier [lattice-wspecifier]]\n" 75 "Note: lattices, if output, will just be linear sequences; use gmm-latgen-faster\n" 76 " if you want \"real\" lattices.\n";
78 bool allow_partial =
true;
81 std::string word_syms_filename;
84 po.
Register(
"acoustic-scale", &acoustic_scale,
85 "Scaling factor for acoustic likelihoods");
86 po.
Register(
"word-symbol-table", &word_syms_filename,
87 "Symbol table for words [for debug output]");
88 po.
Register(
"allow-partial", &allow_partial,
89 "Produce output even when final state was not reached");
97 std::string model_rxfilename = po.
GetArg(1),
98 fst_rxfilename = po.
GetArg(2),
99 feature_rspecifier = po.
GetArg(3),
100 words_wspecifier = po.
GetArg(4),
108 Input ki(model_rxfilename, &binary);
109 trans_model.
Read(ki.Stream(), binary);
110 am_gmm.
Read(ki.Stream(), binary);
119 fst::SymbolTable *word_syms = NULL;
120 if (word_syms_filename !=
"")
121 if (!(word_syms = fst::SymbolTable::ReadText(word_syms_filename)))
122 KALDI_ERR <<
"Could not read symbol table from file " 123 << word_syms_filename;
132 fst::Fst<fst::StdArc> *decode_fst =
ReadNetwork(fst_rxfilename);
135 kaldi::int64 frame_count = 0;
136 int num_success = 0, num_fail = 0;
141 for (; !feature_reader.
Done(); feature_reader.
Next()) {
142 std::string key = feature_reader.
Key();
145 if (features.NumRows() == 0) {
146 KALDI_WARN <<
"Zero-length utterance: " << key;
153 decoder.
Decode(&gmm_decodable);
155 fst::VectorFst<LatticeArc> decoded;
160 KALDI_WARN <<
"Decoder did not reach end-state, " 161 <<
"outputting partial traceback since --allow-partial=true";
163 std::vector<int32> alignment;
164 std::vector<int32>
words;
166 frame_count += features.NumRows();
170 words_writer.
Write(key, words);
171 if (alignment_writer.
IsOpen())
172 alignment_writer.
Write(key, alignment);
174 if (lattice_wspecifier !=
"") {
176 if (acoustic_scale != 0.0)
179 fst::VectorFst<CompactLatticeArc> clat;
181 clat_writer.
Write(key, clat);
184 if (word_syms != NULL) {
185 std::cerr << key <<
' ';
186 for (
size_t i = 0;
i < words.size();
i++) {
187 std::string s = word_syms->Find(words[
i]);
189 KALDI_ERR <<
"Word-id " << words[
i] <<
" not in symbol table.";
190 std::cerr << s <<
' ';
196 KALDI_LOG <<
"Log-like per frame for utterance " << key <<
" is " 197 << (like / features.NumRows()) <<
" over " 198 << features.NumRows() <<
" frames.";
199 KALDI_VLOG(2) <<
"Cost for utterance " << key <<
" is " 203 KALDI_WARN <<
"Did not successfully decode utterance " << key
204 <<
", len = " << features.NumRows();
208 double elapsed = timer.
Elapsed();
209 KALDI_LOG <<
"Time taken [excluding initialization] "<< elapsed
210 <<
"s: real-time factor assuming 100 frames/sec is " 211 << (elapsed*100.0/frame_count);
212 KALDI_LOG <<
"Done " << num_success <<
" utterances, failed for " 214 KALDI_LOG <<
"Overall log-likelihood per frame is " << (tot_like/frame_count) <<
" over " 215 << frame_count<<
" frames.";
219 return (num_success != 0 ? 0 : 1);
220 }
catch(
const std::exception &e) {
221 std::cerr << e.what();
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
fst::Fst< fst::StdArc > * ReadNetwork(std::string filename)
void PrintUsage(bool print_command_line=false)
Prints the usage documentation [provided in the constructor].
void Decode(DecodableInterface *decodable)
A templated class for writing objects to an archive or script file; see The Table concept...
bool GetLinearSymbolSequence(const Fst< Arc > &fst, std::vector< I > *isymbols_out, std::vector< I > *osymbols_out, typename Arc::Weight *tot_weight_out)
GetLinearSymbolSequence gets the symbol sequence from a linear FST.
void Write(const std::string &key, const T &value) const
void Register(const std::string &name, bool *ptr, const std::string &doc)
bool GetBestPath(fst::MutableFst< LatticeArc > *fst_out, bool use_final_probs=true)
GetBestPath gets the decoding traceback.
std::vector< std::vector< double > > AcousticLatticeScale(double acwt)
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
void ScaleLattice(const std::vector< std::vector< ScaleFloat > > &scale, MutableFst< ArcTpl< Weight > > *fst)
Scales the pairs of weights in LatticeWeight or CompactLatticeWeight by viewing the pair (a...
void Read(std::istream &is, bool binary)
void ConvertLattice(const ExpandedFst< ArcTpl< Weight > > &ifst, MutableFst< ArcTpl< CompactLatticeWeightTpl< Weight, Int > > > *ofst, bool invert)
Convert lattice from a normal FST to a CompactLattice FST.
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.
int main(int argc, char *argv[])
std::string GetArg(int param) const
Returns one of the positional parameters; 1-based indexing for argc/argv compatibility.
void Register(OptionsItf *opts, bool full)
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)
bool ReachedFinal() const
Returns true if a final state was active on the last frame.
std::string GetOptArg(int param) const