31 const std::string &utt,
35 int32 min_len = in[0].NumRows(),
36 max_len = in[0].NumRows(),
37 tot_dim = in[0].NumCols();
38 for (
int32 i = 1;
i < in.size();
i++) {
39 int32 len = in[
i].NumRows(), dim = in[
i].NumCols();
41 if(len < min_len) min_len = len;
42 if(len > max_len) max_len = len;
44 if (max_len - min_len > tolerance || min_len == 0) {
45 KALDI_WARN <<
"Length mismatch " << max_len <<
" vs. " << min_len
46 << (utt.empty() ?
"" :
" for utt ") << utt
47 <<
" exceeds tolerance " << tolerance;
51 if (max_len - min_len > 0) {
52 KALDI_VLOG(2) <<
"Length mismatch " << max_len <<
" vs. " << min_len
53 << (utt.empty() ?
"" :
" for utt ") << utt
54 <<
" within tolerance " << tolerance;
56 out->
Resize(min_len, tot_dim);
58 for (
int32 i = 0;
i < in.size();
i++) {
59 int32 this_dim = in[
i].NumCols();
60 out->
Range(0, min_len, dim_offset, this_dim).CopyFromMat(
61 in[
i].Range(0, min_len, 0, this_dim));
62 dim_offset += this_dim;
70 int main(
int argc,
char *argv[]) {
72 using namespace kaldi;
76 "Paste feature files (assuming they have about the same durations,\n" 77 "see --length-tolerance), appending the features on each frame;\n" 78 "think of the unix command 'paste'.\n" 79 "Usage: paste-feats <in-rspecifier1> <in-rspecifier2> [<in-rspecifier3> ...] <out-wspecifier>\n" 80 " or: paste-feats <in-rxfilename1> <in-rxfilename2> [<in-rxfilename3> ...] <out-wxfilename>\n" 81 " e.g. paste-feats ark:feats1.ark \"ark:select-feats 0-3 ark:feats2.ark ark:- |\" ark:feats-out.ark\n" 82 " or: paste-feats foo.mat bar.mat baz.mat\n" 83 "See also: copy-feats, copy-matrix, append-vector-to-feats, concat-feats\n";
87 int32 length_tolerance = 0;
89 po.
Register(
"length-tolerance", &length_tolerance,
90 "If length is different, trim as shortest up to a frame " 91 " difference of length-tolerance, otherwise exclude segment.");
92 po.
Register(
"binary", &binary,
"If true, output files in binary " 93 "(only relevant for single-file operation, i.e. no tables)");
111 string rspecifier1 = po.
GetArg(1);
115 vector<RandomAccessBaseFloatMatrixReader *> input;
117 string rspecifier = po.
GetArg(
i);
122 int32 num_done = 0, num_err = 0;
125 for (; !input1.
Done(); input1.
Next()) {
126 string utt = input1.
Key();
127 KALDI_VLOG(2) <<
"Merging features for utterance " << utt;
130 vector<Matrix<BaseFloat> > feats(po.
NumArgs() - 1);
131 feats[0] = input1.
Value();
133 for (i = 0; i < static_cast<int32>(input.size()); i++) {
134 if (input[i]->HasKey(utt)) {
135 feats[i + 1] = input[
i]->Value(utt);
137 KALDI_WARN <<
"Missing utt " << utt <<
" from input " 143 if (i != static_cast<int32>(input.size()))
146 if (!
AppendFeats(feats, utt, length_tolerance, &output)) {
150 feat_writer.
Write(utt, output);
154 for (
int32 i=0;
i < input.size();
i++)
158 KALDI_LOG <<
"Done " << num_done <<
" utts, errors on " 161 return (num_done == 0 ? -1 : 0);
164 std::vector<Matrix<BaseFloat> > feats(po.
NumArgs() - 1);
168 if (!
AppendFeats(feats,
"", length_tolerance, &output))
172 KALDI_LOG <<
"Wrote appended features to " << output_wxfilename;
175 }
catch(
const std::exception &e) {
176 std::cerr << e.what();
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
RandomAccessTableReader< KaldiObjectHolder< Matrix< BaseFloat > > > RandomAccessBaseFloatMatrixReader
void PrintUsage(bool print_command_line=false)
Prints the usage documentation [provided in the constructor].
int main(int argc, char *argv[])
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)
RspecifierType ClassifyRspecifier(const std::string &rspecifier, std::string *rxfilename, RspecifierOptions *opts)
void ReadKaldiObject(const std::string &filename, Matrix< float > *m)
Allows random access to a collection of objects in an archive or script file; see The Table concept...
bool AppendFeats(const std::vector< Matrix< BaseFloat > > &in, const std::string &utt, int32 tolerance, Matrix< BaseFloat > *out)
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).
void WriteKaldiObject(const C &c, const std::string &filename, bool binary)
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.
void Resize(const MatrixIndexT r, const MatrixIndexT c, MatrixResizeType resize_type=kSetZero, MatrixStrideType stride_type=kDefaultStride)
Sets matrix to a specified size (zero is OK as long as both r and c are zero).