fstcopy.cc
Go to the documentation of this file.
1 // fstbin/fstcopy.cc
2 
3 // Copyright 2009-2011 Microsoft Corporation
4 
5 // See ../../COPYING for clarification regarding multiple authors
6 //
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 //
11 // http://www.apache.org/licenses/LICENSE-2.0
12 //
13 // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
15 // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
16 // MERCHANTABLITY OR NON-INFRINGEMENT.
17 // See the Apache 2 License for the specific language governing permissions and
18 // limitations under the License.
19 
20 
21 #include "base/kaldi-common.h"
22 #include "util/common-utils.h"
23 #include "fst/fstlib.h"
24 #include "fstext/table-matcher.h"
25 #include "fstext/fstext-utils.h"
26 #include "fstext/kaldi-fst-io.h"
27 
28 /*
29 Test:
30 the command below should print out something similar to the given
31 input. and if you remove ,t from the output side it should print something
32 binary.
33 cat <<EOF | fstcopy ark,t:- ark,t:-
34 foo
35 0 1 9 9
36 1 0.0
37 
38 EOF
39 
40 */
41 int main(int argc, char *argv[]) {
42  try {
43  using namespace kaldi;
44  using namespace fst;
45  using kaldi::int32;
46 
47  const char *usage =
48  "Copy tables/archives of FSTs, indexed by a string (e.g. utterance-id)\n"
49  "\n"
50  "Usage: fstcopy <fst-rspecifier> <fst-wspecifier>\n";
51 
52  ParseOptions po(usage);
53 
54  po.Read(argc, argv);
55 
56  if (po.NumArgs() != 2) {
57  po.PrintUsage();
58  exit(1);
59  }
60 
61  std::string fst_rspecifier = po.GetArg(1),
62  fst_wspecifier = po.GetArg(2);
63 
64  SequentialTableReader<VectorFstHolder> fst_reader(fst_rspecifier);
65  TableWriter<VectorFstHolder> fst_writer(fst_wspecifier);
66  int32 n_done = 0;
67 
68  for (; !fst_reader.Done(); fst_reader.Next(), n_done++)
69  fst_writer.Write(fst_reader.Key(), fst_reader.Value());
70 
71  KALDI_LOG << "Copied " << n_done << " FSTs.";
72  return (n_done != 0 ? 0 : 1);
73  } catch(const std::exception &e) {
74  std::cerr << e.what();
75  return -1;
76  }
77 }
78 
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 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...
Definition: kaldi-table.h:368
kaldi::int32 int32
void Write(const std::string &key, const T &value) const
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
Definition: parse-options.h:36
int main(int argc, char *argv[])
Definition: fstcopy.cc:41
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
Definition: kaldi-table.h:287
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.
int NumArgs() const
Number of positional parameters (c.f. argc-1).
#define KALDI_LOG
Definition: kaldi-error.h:153