30 int main(
int argc,
char *argv[]) {
32 using namespace kaldi;
36 "Select certain dimensions of the feature file; think of it as the unix\n" 37 "command cut -f ...\n" 38 "Usage: select-feats <selection> <in-rspecifier> <out-wspecifier>\n" 39 " e.g. select-feats 0,24-22,3-12 scp:feats.scp ark,scp:feat-red.ark,feat-red.scp\n" 40 "See also copy-feats, extract-feature-segments, subset-feats, subsample-feats\n";
51 string sspecifier = po.
GetArg(1);
52 string rspecifier = po.
GetArg(2);
53 string wspecifier = po.
GetArg(3);
58 if (kaldi_reader.
Done()) {
67 istringstream iss(sspecifier);
69 vector<pair<int32, int32> > ranges;
70 vector<int32> offsets;
71 while (getline(iss, token,
',')) {
72 size_t p = token.find(
'-');
73 if (p != string::npos) {
75 istringstream(token.substr(0, token.length() - p - 1)) >> s;
76 istringstream(token.substr(p+1)) >> e;
78 if (s < 0 || s > (dim_in-1)) {
79 KALDI_ERR <<
"Invalid range start: " << s;
81 }
else if (e < 0 || e > (dim_in-1)) {
89 ranges.push_back(pair<int32, int32>(
i,
i));
90 offsets.push_back(dim_out);
94 ranges.push_back(pair<int32, int32>(s, e));
95 offsets.push_back(dim_out);
96 dim_out += (e - s + 1);
100 istringstream(token) >>
i;
102 if (i < 0 || i > (dim_in - 1)) {
103 KALDI_ERR <<
"Invalid selection index: " <<
i;
107 ranges.push_back(pair<int32, int32>(i, i));
108 offsets.push_back(dim_out);
113 if (ranges.size() < 1) {
114 KALDI_ERR <<
"No ranges or indices in selection string!";
122 for (; !kaldi_reader.
Done(); kaldi_reader.
Next()) {
126 for (
int32 i = 0;
i < ranges.size(); ++
i) {
127 int32 f = ranges[
i].first;
128 int32 ncol = ranges[
i].second - f + 1;
130 feats.
Range(0, feats.NumRows(), offsets[
i], ncol)
131 .CopyFromMat(kaldi_reader.
Value().Range(0, feats.NumRows(), f, ncol));
134 kaldi_writer.
Write(kaldi_reader.
Key(), feats);
138 }
catch(
const std::exception &e) {
139 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
int main(int argc, char *argv[])
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...
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).
SubMatrix< Real > Range(const MatrixIndexT row_offset, const MatrixIndexT num_rows, const MatrixIndexT col_offset, const MatrixIndexT num_cols) const
Return a sub-part of matrix.