27 int main(
int argc,
char *argv[]) {
29 using namespace kaldi;
31 typedef kaldi::int64 int64;
32 using fst::SymbolTable;
37 "Generate 1-best path through lattices; output as transcriptions and alignments\n" 38 "Note: if you want output as FSTs, use lattice-1best; if you want output\n" 39 "with acoustic and LM scores, use lattice-1best | nbest-to-linear\n" 40 "Usage: lattice-best-path [options] <lattice-rspecifier> [ <transcriptions-wspecifier> [ <alignments-wspecifier>] ]\n" 41 " e.g.: lattice-best-path --acoustic-scale=0.1 ark:1.lats 'ark,t:|int2sym.pl -f 2- words.txt > text' ark:1.ali\n";
47 std::string word_syms_filename;
48 po.
Register(
"acoustic-scale", &acoustic_scale,
"Scaling factor for acoustic likelihoods");
49 po.
Register(
"lm-scale", &lm_scale,
"Scaling factor for LM probabilities. " 50 "Note: the ratio acoustic-scale/lm-scale is all that matters.");
51 po.
Register(
"word-symbol-table", &word_syms_filename,
"Symbol table for words [for debug output]");
60 std::string lats_rspecifier = po.
GetArg(1),
61 transcriptions_wspecifier = po.
GetOptArg(2),
70 fst::SymbolTable *word_syms = NULL;
71 if (word_syms_filename !=
"")
72 if (!(word_syms = fst::SymbolTable::ReadText(word_syms_filename)))
73 KALDI_ERR <<
"Could not read symbol table from file " 74 << word_syms_filename;
77 int32 n_done = 0, n_fail = 0;
81 for (; !clat_reader.
Done(); clat_reader.
Next()) {
82 std::string key = clat_reader.
Key();
91 if (best_path.Start() == fst::kNoStateId) {
92 KALDI_WARN <<
"Best-path failed for key " << key;
95 std::vector<int32> alignment;
96 std::vector<int32>
words;
99 KALDI_LOG <<
"For utterance " << key <<
", best cost " 102 <<
" over " << alignment.size() <<
" frames.";
103 if (transcriptions_wspecifier !=
"")
104 transcriptions_writer.
Write(key, words);
105 if (alignments_wspecifier !=
"")
106 alignments_writer.
Write(key, alignment);
107 if (word_syms != NULL) {
108 std::cerr << key <<
' ';
109 for (
size_t i = 0;
i < words.size();
i++) {
110 std::string s = word_syms->Find(words[
i]);
112 KALDI_ERR <<
"Word-id " << words[
i] <<
" not in symbol table.";
113 std::cerr << s <<
' ';
118 n_frame += alignment.size();
119 tot_weight =
Times(tot_weight, weight);
124 KALDI_LOG <<
"Overall cost per frame is " << (tot_weight_float/n_frame)
125 <<
" = " << (tot_weight.
Value1()/n_frame) <<
" [graph]" 126 <<
" + " << (tot_weight.
Value2()/n_frame) <<
" [acoustic]" 127 <<
" over " << n_frame <<
" frames.";
128 KALDI_LOG <<
"Done " << n_done <<
" lattices, failed for " << n_fail;
131 if (n_done != 0)
return 0;
133 }
catch(
const std::exception &e) {
134 std::cerr << e.what();
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
static const LatticeWeightTpl One()
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 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)
int main(int argc, char *argv[])
void CompactLatticeShortestPath(const CompactLattice &clat, CompactLattice *shortest_path)
A form of the shortest-path/best-path algorithm that's specially coded for CompactLattice.
LatticeWeightTpl< FloatType > Times(const LatticeWeightTpl< FloatType > &w1, const LatticeWeightTpl< FloatType > &w2)
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 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...
std::vector< std::vector< double > > LatticeScale(double lmwt, double acwt)
fst::VectorFst< LatticeArc > Lattice
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.
fst::VectorFst< CompactLatticeArc > CompactLattice
int NumArgs() const
Number of positional parameters (c.f. argc-1).
std::string GetOptArg(int param) const