27 int main(
int argc,
char *argv[]) {
29 using namespace kaldi;
32 "Compose (affine or linear) feature transforms\n" 33 "Usage: compose-transforms [options] (<transform-A-rspecifier>|<transform-A-rxfilename>) " 34 "(<transform-B-rspecifier>|<transform-B-rxfilename>) (<transform-out-wspecifier>|<transform-out-wxfilename>)\n" 35 " Note: it does matrix multiplication (A B) so B is the transform that gets applied\n" 36 " to the features first. If b-is-affine = true, then assume last column of b corresponds to offset\n" 37 " e.g.: compose-transforms 1.mat 2.mat 3.mat\n" 38 " compose-transforms 1.mat ark:2.trans ark:3.trans\n" 39 " compose-transforms ark:1.trans ark:2.trans ark:3.trans\n" 40 " See also: transform-feats, transform-vec, extend-transform-dim, est-lda, est-pca\n";
42 bool b_is_affine =
false;
44 std::string utt2spk_rspecifier;
47 po.
Register(
"utt2spk", &utt2spk_rspecifier,
"rspecifier for utterance to speaker map (if mixing utterance and speaker ids)");
49 po.
Register(
"b-is-affine", &b_is_affine,
"If true, treat last column of transform b as an offset term (only relevant if a is affine)");
50 po.
Register(
"binary", &binary,
"Write in binary mode (only relevant if output is a wxfilename)");
60 std::string transform_a_fn = po.
GetArg(1);
61 std::string transform_b_fn = po.
GetArg(2);
62 std::string transform_c_fn = po.
GetArg(3);
66 bool a_is_rspecifier =
78 if (utt2spk_rspecifier !=
"") {
79 if (!(a_is_rspecifier && b_is_rspecifier))
80 KALDI_ERR <<
"Error: utt2spk option provided compose transforms but " 81 "at least one of the inputs is a global transform.";
82 if (!utt2spk_reader.
Open(utt2spk_rspecifier))
83 KALDI_ERR <<
"Error upening utt2spk map from " 84 << utt2spk_rspecifier;
88 if ( (a_is_rspecifier || b_is_rspecifier) != c_is_wspecifier)
89 KALDI_ERR <<
"Formats of the input and output rspecifiers/rxfilenames do " 90 "not match (if either a or b is an rspecifier, then the output must " 94 if (a_is_rspecifier || b_is_rspecifier) {
96 if (a_is_rspecifier) {
98 if (b_is_rspecifier) {
100 for (;!a_reader.
Done(); a_reader.
Next()) {
101 if (utt2spk_rspecifier !=
"") {
102 std::string utt = a_reader.
Key();
103 if (!utt2spk_reader.
HasKey(utt)) {
104 KALDI_WARN <<
"No speaker provided for utterance " << utt
105 <<
" (perhaps you wrongly provided utt2spk option to " 106 " compose-transforms?)";
109 std::string spk = utt2spk_reader.
Value(utt);
110 if (!b_reader.
HasKey(spk)) {
111 KALDI_WARN <<
"Second table does not have key " << spk;
118 c_writer.
Write(utt, c);
121 KALDI_WARN <<
"Second table does not have key " << a_reader.
Key();
134 for (;!a_reader.
Done(); a_reader.
Next()) {
146 for (; !b_reader.
Done(); b_reader.
Next()) {
162 KALDI_WARN <<
"It looks like you are trying to compose two affine transforms" 163 <<
", but you omitted the --b-is-affine option.";
169 }
catch(
const std::exception &e) {
170 std::cerr << e.what();
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
MatrixIndexT NumCols() const
Returns number of columns (or zero for empty matrix).
void PrintUsage(bool print_command_line=false)
Prints the usage documentation [provided in the constructor].
bool Open(const std::string &rspecifier)
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...
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
const T & Value(const std::string &key)
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.
bool HasKey(const std::string &key)
WspecifierType ClassifyWspecifier(const std::string &wspecifier, std::string *archive_wxfilename, std::string *script_wxfilename, WspecifierOptions *opts)
int NumArgs() const
Number of positional parameters (c.f. argc-1).
bool ComposeTransforms(const Matrix< BaseFloat > &a, const Matrix< BaseFloat > &b, bool b_is_affine, Matrix< BaseFloat > *c)
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
void WriteKaldiObject(const C &c, const std::string &filename, bool binary)