fsts-project.cc File Reference
Include dependency graph for fsts-project.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 27 of file fsts-project.cc.

References SequentialTableReader< Holder >::Done(), ParseOptions::GetArg(), KALDI_LOG, SequentialTableReader< Holder >::Key(), SequentialTableReader< Holder >::Next(), ParseOptions::NumArgs(), ParseOptions::PrintUsage(), ParseOptions::Read(), ParseOptions::Register(), SequentialTableReader< Holder >::Value(), and TableWriter< Holder >::Write().

27  {
28  try {
29  using namespace kaldi;
30  using namespace fst;
31  typedef kaldi::int32 int32;
32  typedef kaldi::uint64 uint64;
33 
34  const char *usage =
35  "Reads kaldi archive of FSTs; for each element, performs the project\n"
36  "operation either on input (default) or on the output (if the option\n"
37  "--project-output is true).\n"
38  "\n"
39  "Usage: fsts-project [options] <fsts-rspecifier> <fsts-wspecifier>\n"
40  " e.g.: fsts-project ark:train.fsts ark,t:train.fsts\n"
41  "\n"
42  "see also: fstproject (from the OpenFst toolkit)\n";
43 
44  ParseOptions po(usage);
45 
46  bool project_output = false;
47 
48  po.Register("project-output", &project_output,
49  "If true, project output vs input");
50 
51  po.Read(argc, argv);
52 
53  if (po.NumArgs() != 2) {
54  po.PrintUsage();
55  exit(1);
56  }
57 
58  std::string fsts_rspecifier = po.GetArg(1),
59  fsts_wspecifier = po.GetArg(2);
60 
61 
62  SequentialTableReader<VectorFstHolder> fst_reader(fsts_rspecifier);
63  TableWriter<VectorFstHolder> fst_writer(fsts_wspecifier);
64 
65  int32 n_done = 0;
66  for (; !fst_reader.Done(); fst_reader.Next()) {
67  std::string key = fst_reader.Key();
68  VectorFst<StdArc> fst(fst_reader.Value());
69 
70  Project(&fst, project_output ? PROJECT_OUTPUT : PROJECT_INPUT);
71 
72  fst_writer.Write(key, fst);
73  n_done++;
74  }
75 
76  KALDI_LOG << "Projected " << n_done << " FSTs";
77  return (n_done != 0 ? 0 : 1);
78  } catch(const std::exception &e) {
79  std::cerr << e.what();
80  return -1;
81  }
82 }
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
A templated class for writing objects to an archive or script file; see The Table concept...
Definition: kaldi-table.h:368
kaldi::int32 int32
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
Definition: parse-options.h:36
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
Definition: kaldi-table.h:287
#define KALDI_LOG
Definition: kaldi-error.h:153