fstaddselfloops.cc File Reference
#include "base/kaldi-common.h"
#include "util/common-utils.h"
#include "fst/fstlib.h"
#include "fstext/determinize-star.h"
#include "fstext/fstext-utils.h"
#include "fstext/kaldi-fst-io.h"
Include dependency graph for fstaddselfloops.cc:

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 36 of file fstaddselfloops.cc.

References kaldi::AddSelfLoops(), ParseOptions::GetArg(), ParseOptions::GetOptArg(), KALDI_ERR, ParseOptions::NumArgs(), kaldi::PrintableRxfilename(), ParseOptions::PrintUsage(), ParseOptions::Read(), fst::ReadFstKaldi(), kaldi::ReadIntegerVectorSimple(), and fst::WriteFstKaldi().

36  {
37  try {
38  using namespace kaldi;
39  using namespace fst;
40  using kaldi::int32;
41 
42  const char *usage =
43  "Adds self-loops to states of an FST to propagate disambiguation symbols through it\n"
44  "They are added on each final state and each state with non-epsilon output symbols\n"
45  "on at least one arc out of the state. Useful in conjunction with predeterminize\n"
46  "\n"
47  "Usage: fstaddselfloops in-disambig-list out-disambig-list [in.fst [out.fst] ]\n"
48  "E.g: fstaddselfloops in.list out.list < in.fst > withloops.fst\n"
49  "in.list and out.list are lists of integers, one per line, of the\n"
50  "same length.\n";
51 
52  ParseOptions po(usage);
53  po.Read(argc, argv);
54 
55  if (po.NumArgs() < 2 || po.NumArgs() > 4) {
56  po.PrintUsage();
57  exit(1);
58  }
59 
60  std::string disambig_in_rxfilename = po.GetArg(1),
61  disambig_out_rxfilename = po.GetArg(2),
62  fst_in_filename = po.GetOptArg(3),
63  fst_out_filename = po.GetOptArg(4);
64 
65  VectorFst<StdArc> *fst = ReadFstKaldi(fst_in_filename);
66 
67  std::vector<int32> disambig_in;
68  if (!ReadIntegerVectorSimple(disambig_in_rxfilename, &disambig_in))
69  KALDI_ERR << "fstaddselfloops: Could not read disambiguation symbols from "
70  << kaldi::PrintableRxfilename(disambig_in_rxfilename);
71 
72  std::vector<int32> disambig_out;
73  if (!ReadIntegerVectorSimple(disambig_out_rxfilename, &disambig_out))
74  KALDI_ERR << "fstaddselfloops: Could not read disambiguation symbols from "
75  << kaldi::PrintableRxfilename(disambig_out_rxfilename);
76 
77  if (disambig_in.size() != disambig_out.size())
78  KALDI_ERR << "fstaddselfloops: mismatch in size of disambiguation symbols";
79 
80  AddSelfLoops(fst, disambig_in, disambig_out);
81 
82  WriteFstKaldi(*fst, fst_out_filename);
83 
84  delete fst;
85 
86  return 0;
87  } catch(const std::exception &e) {
88  std::cerr << e.what();
89  return -1;
90  }
91  return 0;
92 }
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
For an extended explanation of the framework of which grammar-fsts are a part, please see Support for...
Definition: graph.dox:21
void AddSelfLoops(const TransitionModel &trans_model, const std::vector< int32 > &disambig_syms, BaseFloat self_loop_scale, bool reorder, bool check_no_self_loops, fst::VectorFst< fst::StdArc > *fst)
For context, see AddSelfLoops().
Definition: hmm-utils.cc:602
kaldi::int32 int32
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
Definition: parse-options.h:36
#define KALDI_ERR
Definition: kaldi-error.h:147
void WriteFstKaldi(std::ostream &os, bool binary, const VectorFst< Arc > &t)
void ReadFstKaldi(std::istream &is, bool binary, VectorFst< Arc > *fst)
std::string PrintableRxfilename(const std::string &rxfilename)
PrintableRxfilename turns the rxfilename into a more human-readable form for error reporting...
Definition: kaldi-io.cc:61
bool ReadIntegerVectorSimple(const std::string &rxfilename, std::vector< int32 > *list)
ReadFromList attempts to read this list of integers, one per line, from the given file...