copy-int-vector.cc File Reference
Include dependency graph for copy-int-vector.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 26 of file copy-int-vector.cc.

References kaldi::ClassifyRspecifier(), kaldi::ClassifyWspecifier(), SequentialTableReader< Holder >::Done(), ParseOptions::GetArg(), KALDI_ERR, KALDI_LOG, SequentialTableReader< Holder >::Key(), kaldi::kNoRspecifier, kaldi::kNoWspecifier, SequentialTableReader< Holder >::Next(), ParseOptions::NumArgs(), ParseOptions::PrintUsage(), ParseOptions::Read(), kaldi::ReadIntegerVector(), ParseOptions::Register(), Input::Stream(), SequentialTableReader< Holder >::Value(), TableWriter< Holder >::Write(), and kaldi::WriteIntegerVector().

26  {
27  try {
28  using namespace kaldi;
29 
30  const char *usage =
31  "Copy vectors of integers, or archives of vectors of integers \n"
32  "(e.g. alignments)\n"
33  "\n"
34  "Usage: copy-int-vector [options] (vector-in-rspecifier|vector-in-rxfilename) (vector-out-wspecifier|vector-out-wxfilename)\n"
35  " e.g.: copy-int-vector --binary=false foo -\n"
36  " copy-int-vector ark:1.ali ark,t:-\n";
37 
38  bool binary = true;
39  ParseOptions po(usage);
40 
41  po.Register("binary", &binary, "Write in binary mode (only relevant if output is a wxfilename)");
42 
43  po.Read(argc, argv);
44 
45  if (po.NumArgs() != 2) {
46  po.PrintUsage();
47  exit(1);
48  }
49 
50 
51  std::string vector_in_fn = po.GetArg(1),
52  vector_out_fn = po.GetArg(2);
53 
54  // all these "fn"'s are either rspecifiers or filenames.
55 
56  bool in_is_rspecifier =
57  (ClassifyRspecifier(vector_in_fn, NULL, NULL)
58  != kNoRspecifier),
59  out_is_wspecifier =
60  (ClassifyWspecifier(vector_out_fn, NULL, NULL, NULL)
61  != kNoWspecifier);
62 
63  if (in_is_rspecifier != out_is_wspecifier)
64  KALDI_ERR << "Cannot mix archives with regular files (copying vectors)";
65 
66  if (!in_is_rspecifier) {
67  std::vector<int32> vec;
68  {
69  bool binary_in;
70  Input ki(vector_in_fn, &binary_in);
71  ReadIntegerVector(ki.Stream(), binary_in, &vec);
72  }
73  Output ko(vector_out_fn, binary);
74  WriteIntegerVector(ko.Stream(), binary, vec);
75  KALDI_LOG << "Copied vector to " << vector_out_fn;
76  return 0;
77  } else {
78  int num_done = 0;
79  Int32VectorWriter writer(vector_out_fn);
80  SequentialInt32VectorReader reader(vector_in_fn);
81  for (; !reader.Done(); reader.Next(), num_done++)
82  writer.Write(reader.Key(), reader.Value());
83  KALDI_LOG << "Copied " << num_done << " vectors of int32.";
84  return (num_done != 0 ? 0 : 1);
85  }
86  } catch(const std::exception &e) {
87  std::cerr << e.what();
88  return -1;
89  }
90 }
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
A templated class for writing objects to an archive or script file; see The Table concept...
Definition: kaldi-table.h:368
RspecifierType ClassifyRspecifier(const std::string &rspecifier, std::string *rxfilename, RspecifierOptions *opts)
Definition: kaldi-table.cc:225
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
Definition: parse-options.h:36
void ReadIntegerVector(std::istream &is, bool binary, std::vector< T > *v)
Function for reading STL vector of integer types.
Definition: io-funcs-inl.h:232
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
Definition: kaldi-table.h:287
#define KALDI_ERR
Definition: kaldi-error.h:147
WspecifierType ClassifyWspecifier(const std::string &wspecifier, std::string *archive_wxfilename, std::string *script_wxfilename, WspecifierOptions *opts)
Definition: kaldi-table.cc:135
void WriteIntegerVector(std::ostream &os, bool binary, const std::vector< T > &v)
Function for writing STL vectors of integer types.
Definition: io-funcs-inl.h:198
#define KALDI_LOG
Definition: kaldi-error.h:153