30 int main(
int argc,
char *argv[]) {
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.");
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++) {
102 feat_writer.
Write(utt, output);
107 for (
int32 i = 0;
i < output.NumRows();
i++)
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...
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...
void Write(const std::string &key, const T &value) const
void Register(const std::string &name, bool *ptr, const std::string &doc)
void CopyFromVec(const VectorBase< Real > &v)
Copy data from another vector (must match own size).
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].
int main(int argc, char *argv[])
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
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_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...