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";
46 if (po.NumArgs() != 3) {
51 string sspecifier = po.GetArg(1);
52 string rspecifier = po.GetArg(2);
53 string wspecifier = po.GetArg(3);
58 if (kaldi_reader.Done()) {
63 int32 dim_in = kaldi_reader.Value().NumCols();
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...
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...
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
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.