37 int main(
int argc,
char *argv[]) {
39 using namespace kaldi;
42 "Save features as Sphinx files:\n" 43 "Each utterance will be stored as a unique Sphinx file in a specified directory.\n" 44 "The Sphinx filename will correspond to the utterance-id (key) in the input table, with the specified extension.\n" 45 "Usage: copy-feats-to-sphinx [options] in-rspecifier\n" 46 "Example: copy-feats-to-sphinx --output-dir=/tmp/sphinx-features --output-ext=fea scp:feats.scp\n";
49 std::string dir_out =
"./";
50 std::string ext_out =
"mfc";
52 po.
Register(
"output-ext", &ext_out,
"Output extension of sphinx files");
53 po.
Register(
"output-dir", &dir_out,
"Output directory");
62 std::string rspecifier = po.
GetArg(1);
65 const char * c = dir_out.c_str();
66 if ( access( c, 0 ) != 0 ){
70 if (mkdir(c, S_IRWXU|S_IRGRP|S_IXGRP) != 0)
72 KALDI_ERR <<
"Could not create output directory: " << dir_out;
76 int32 num_frames, dim, num_done=0;
78 for (; !feats_reader.
Done(); feats_reader.
Next()) {
79 std::string utt = feats_reader.
Key();
85 ss << dir_out <<
"/" << utt <<
"." << ext_out;
86 output.
Range(0, num_frames, 0, dim).CopyFromMat(feats.
Range(0, num_frames, 0, dim));
87 std::ofstream os(ss.str().c_str(), std::ios::out|std::ios::binary);
91 KALDI_LOG << num_done <<
" Sphinx feature files generated in the direcory: " << dir_out;
92 return (num_done != 0 ? 0 : 1);
94 }
catch(
const std::exception &e) {
95 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 WriteSphinx(std::ostream &os, const MatrixBase< Real > &M)
void Register(const std::string &name, bool *ptr, const std::string &doc)
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).
int main(int argc, char *argv[])
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
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.