28 using namespace kaldi;
31 "Copy features [and possibly change format]\n" 32 "Usage: copy-feats [options] <feature-rspecifier> <feature-wspecifier>\n" 33 "or: copy-feats [options] <feats-rxfilename> <feats-wxfilename>\n" 34 "e.g.: copy-feats ark:- ark,scp:foo.ark,foo.scp\n" 35 " or: copy-feats ark:foo.ark ark,t:txt.ark\n" 36 "See also: copy-matrix, copy-feats-to-htk, copy-feats-to-sphinx, select-feats,\n" 37 "extract-feature-segments, subset-feats, subsample-feats, splice-feats, paste-feats,\n" 43 bool sphinx_in =
false;
44 bool compress =
false;
45 int32 compression_method_in = 1;
46 std::string num_frames_wspecifier;
47 po.Register(
"htk-in", &htk_in,
"Read input as HTK features");
48 po.Register(
"sphinx-in", &sphinx_in,
"Read input as Sphinx features");
49 po.Register(
"binary", &binary,
"Binary-mode output (not relevant if writing " 51 po.Register(
"compress", &compress,
"If true, write output in compressed form" 52 "(only currently supported for wxfilename, i.e. archive/script," 54 po.Register(
"compression-method", &compression_method_in,
55 "Only relevant if --compress=true; the method (1 through 7) to " 56 "compress the matrix. Search for CompressionMethod in " 57 "src/matrix/compressed-matrix.h.");
58 po.Register(
"write-num-frames", &num_frames_wspecifier,
59 "Wspecifier to write length in frames of each utterance. " 60 "e.g. 'ark,t:utt2num_frames'. Only applicable if writing tables, " 61 "not when this program is writing individual files. See also " 66 if (po.NumArgs() != 2) {
74 compression_method_in);
78 std::string rspecifier = po.GetArg(1);
79 std::string wspecifier = po.GetArg(2);
80 Int32Writer num_frames_writer(num_frames_wspecifier);
86 for (; !htk_reader.Done(); htk_reader.Next(), num_done++) {
87 kaldi_writer.Write(htk_reader.Key(), htk_reader.Value().first);
88 if (!num_frames_wspecifier.empty())
89 num_frames_writer.Write(htk_reader.Key(),
90 htk_reader.Value().first.NumRows());
92 }
else if (sphinx_in) {
94 for (; !sphinx_reader.Done(); sphinx_reader.Next(), num_done++) {
95 kaldi_writer.Write(sphinx_reader.Key(), sphinx_reader.Value());
96 if (!num_frames_wspecifier.empty())
97 num_frames_writer.Write(sphinx_reader.Key(),
98 sphinx_reader.Value().NumRows());
102 for (; !kaldi_reader.Done(); kaldi_reader.Next(), num_done++) {
103 kaldi_writer.Write(kaldi_reader.Key(), kaldi_reader.Value());
104 if (!num_frames_wspecifier.empty())
105 num_frames_writer.Write(kaldi_reader.Key(),
106 kaldi_reader.Value().NumRows());
113 for (; !htk_reader.Done(); htk_reader.Next(), num_done++) {
114 kaldi_writer.Write(htk_reader.Key(),
116 compression_method));
117 if (!num_frames_wspecifier.empty())
118 num_frames_writer.Write(htk_reader.Key(),
119 htk_reader.Value().first.NumRows());
121 }
else if (sphinx_in) {
123 for (; !sphinx_reader.Done(); sphinx_reader.Next(), num_done++) {
124 kaldi_writer.Write(sphinx_reader.Key(),
126 compression_method));
127 if (!num_frames_wspecifier.empty())
128 num_frames_writer.Write(sphinx_reader.Key(),
129 sphinx_reader.Value().NumRows());
133 for (; !kaldi_reader.Done(); kaldi_reader.Next(), num_done++) {
134 kaldi_writer.Write(kaldi_reader.Key(),
136 compression_method));
137 if (!num_frames_wspecifier.empty())
138 num_frames_writer.Write(kaldi_reader.Key(),
139 kaldi_reader.Value().NumRows());
143 KALDI_LOG <<
"Copied " << num_done <<
" feature matrices.";
144 return (num_done != 0 ? 0 : 1);
146 KALDI_ASSERT(!compress &&
"Compression not yet supported for single files");
147 if (!num_frames_wspecifier.empty())
148 KALDI_ERR <<
"--write-num-frames option not supported when writing/reading " 151 std::string feat_rxfilename = po.GetArg(1), feat_wxfilename = po.GetArg(2);
155 Input ki(feat_rxfilename);
158 ReadHtk(ki.Stream(), &feat_matrix, &header);
159 }
else if (sphinx_in) {
160 KALDI_ERR <<
"For single files, sphinx input is not yet supported.";
168 }
catch(
const std::exception &e) {
169 std::cerr << e.what();
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
A templated class for writing objects to an archive or script file; see The Table concept...
RspecifierType ClassifyRspecifier(const std::string &rspecifier, std::string *rxfilename, RspecifierOptions *opts)
void ReadKaldiObject(const std::string &filename, Matrix< float > *m)
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
#define KALDI_ASSERT(cond)
void WriteKaldiObject(const C &c, const std::string &filename, bool binary)
std::string PrintableRxfilename(const std::string &rxfilename)
PrintableRxfilename turns the rxfilename into a more human-readable form for error reporting...
std::string PrintableWxfilename(const std::string &wxfilename)
PrintableWxfilename turns the wxfilename into a more human-readable form for error reporting...
bool ReadHtk(std::istream &is, Matrix< Real > *M_ptr, HtkHeader *header_ptr)
Extension of the HTK header.