wav-copy.cc File Reference
Include dependency graph for wav-copy.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 wav-copy.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(), kaldi::PrintableRxfilename(), kaldi::PrintableWxfilename(), ParseOptions::PrintUsage(), ParseOptions::Read(), WaveHolder::Read(), Output::Stream(), Input::Stream(), WaveHolder::Value(), SequentialTableReader< Holder >::Value(), WaveHolder::Write(), and TableWriter< Holder >::Write().

26  {
27  try {
28  using namespace kaldi;
29  const char *usage =
30  "Copy wave file or archives of wave files\n"
31  "\n"
32  "Usage: wav-copy [options] <wav-rspecifier> <wav-wspecifier>\n"
33  " or: wav-copy [options] <wav-rxfilename> <wav-wxfilename>\n"
34  "e.g. wav-copy scp:wav.scp ark:-\n"
35  " wav-copy wav.ark:123456 -\n"
36  "See also: wav-to-duration extract-segments\n";
37 
38  ParseOptions po(usage);
39 
40  po.Read(argc, argv);
41 
42  if (po.NumArgs() != 2) {
43  po.PrintUsage();
44  exit(1);
45  }
46 
47  std::string wav_in_fn = po.GetArg(1),
48  wav_out_fn = po.GetArg(2);
49 
50  bool in_is_rspecifier = (ClassifyRspecifier(wav_in_fn, NULL, NULL)
51  != kNoRspecifier),
52  out_is_wspecifier = (ClassifyWspecifier(wav_out_fn, NULL, NULL, NULL)
53  != kNoWspecifier);
54 
55  if (in_is_rspecifier != out_is_wspecifier)
56  KALDI_ERR << "Cannot mix archives with regular files";
57 
58  if (in_is_rspecifier) {
59  int32 num_done = 0;
60 
61  SequentialTableReader<WaveHolder> wav_reader(wav_in_fn);
62  TableWriter<WaveHolder> wav_writer(wav_out_fn);
63 
64  for (; !wav_reader.Done(); wav_reader.Next()) {
65  wav_writer.Write(wav_reader.Key(), wav_reader.Value());
66  num_done++;
67  }
68  KALDI_LOG << "Copied " << num_done << " wave files";
69  return (num_done != 0 ? 0 : 1);
70  } else {
71  bool binary = true;
72  Input ki(wav_in_fn, &binary);
73  Output ko(wav_out_fn, binary, false);
74  WaveHolder wh;
75  if (!wh.Read(ki.Stream())) {
76  KALDI_ERR << "Read failure from "
77  << PrintableRxfilename(wav_in_fn);
78  }
79  if (!WaveHolder::Write(ko.Stream(), true, wh.Value())) {
80  KALDI_ERR << "Write failure to "
81  << PrintableWxfilename(wav_out_fn);
82  }
83  }
84  } catch(const std::exception &e) {
85  std::cerr << e.what();
86  return -1;
87  }
88 }
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
bool Read(std::istream &is)
Definition: wave-reader.h:191
A templated class for writing objects to an archive or script file; see The Table concept...
Definition: kaldi-table.h:368
kaldi::int32 int32
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
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
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
std::string PrintableWxfilename(const std::string &wxfilename)
PrintableWxfilename turns the wxfilename into a more human-readable form for error reporting...
Definition: kaldi-io.cc:73
#define KALDI_LOG
Definition: kaldi-error.h:153
static bool Write(std::ostream &os, bool binary, const T &t)
Definition: wave-reader.h:162