32 using namespace kaldi;
36 "Sub-samples features by taking every n'th frame.\n" 37 "With negative values of n, will repeat each frame n times\n" 38 "(e.g. --n=-2 will repeat each frame twice)\n" 40 "Usage: subsample-feats [options] <in-rspecifier> <out-wspecifier>\n" 41 " e.g. subsample-feats --n=2 ark:- ark:-\n";
47 po.Register(
"n", &n,
"Take every n'th feature, for this value of n" 48 "(with negative value, repeats each feature n times)");
49 po.Register(
"offset", &offset,
"Start with the feature with this offset, " 50 "then take every n'th feature.");
55 "--offset option cannot be used with negative n.");
59 if (po.NumArgs() != 2) {
64 string rspecifier = po.GetArg(1);
65 string wspecifier = po.GetArg(2);
70 int32 num_done = 0, num_err = 0;
71 int64 frames_in = 0, frames_out = 0;
74 for (; !feat_reader.Done(); feat_reader.Next()) {
75 std::string utt = feat_reader.Key();
82 int32 num_indexes = 0;
83 for (
int32 k = offset; k < feats.NumRows(); k +=
n)
87 frames_out += num_indexes;
89 if (num_indexes == 0) {
90 KALDI_WARN <<
"For utterance " << utt <<
", output would have no rows, " 91 <<
"producing no output.";
97 for (
int32 k = offset; k < feats.NumRows(); k +=
n, i++) {
99 dest.CopyFromVec(src);
102 feat_writer.Write(utt, output);
108 output.
Row(i).CopyFromVec(feats.Row(i / repeat));
109 frames_in += feats.NumRows();
110 frames_out += feats.NumRows() * repeat;
111 feat_writer.Write(utt, output);
115 KALDI_LOG <<
"Processed " << num_done <<
" feature matrices; " << num_err
117 KALDI_LOG <<
"Processed " << frames_in <<
" input frames and " 118 << frames_out <<
" output frames.";
119 return (num_done != 0 ? 0 : 1);
120 }
catch(
const std::exception &e) {
121 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...
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
const SubVector< Real > Row(MatrixIndexT i) const
Return specific row of matrix [const].
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
#define KALDI_ASSERT(cond)
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
Represents a non-allocating general vector which can be defined as a sub-vector of higher-level vecto...