37 int main(
int argc,
char *argv[]) {
38 using namespace kaldi;
42 "Build pfiles for neural network training from alignment.\n" 43 "Usage: build-pfile-from-ali [options] <model> <alignments-rspecifier> <feature-rspecifier> \n" 44 "<pfile-wspecifier>\n" 46 " build-pfile-from-ali 1.mdl ark:1.ali features \n" 47 " \"|pfile_create -i - -o pfile.1 -f 143 -l 1\" ";
51 int32 every_nth_frame = 1;
52 po.
Register(
"every-nth-frame", &every_nth_frame,
"This option will cause it to print " 53 "out only every n'th frame (for subsampling)");
62 std::string model_filename = po.
GetArg(1),
63 alignments_rspecifier = po.
GetArg(2),
64 feature_rspecifier = po.
GetArg(3),
65 pfile_wspecifier = po.
GetArg(4);
71 Input ki(model_filename, &binary);
79 int32 num_done = 0, num_no_ali = 0, num_other_error = 0;
84 Output ko(pfile_wspecifier,
false);
86 for (; !feature_reader.
Done(); feature_reader.
Next()) {
87 std::string key = feature_reader.
Key();
88 if (!ali_reader.
HasKey(key)) {
89 KALDI_WARN <<
"Did not find alignment for utterance " << key;
95 std::vector<int32> alignment = ali_reader.
Value(key);
96 if (static_cast<int32>(feats.
NumRows()) != static_cast<int32>(alignment.size())) {
97 KALDI_WARN <<
"Alignment vector has wrong size " << (alignment.size())
98 <<
" vs. " << (feats.
NumRows());
104 for (
size_t i = 0;
i < alignment.size();
i++) {
105 if (
i % every_nth_frame == 0) {
106 std::stringstream ss;
110 ss << (
i / every_nth_frame);
112 for (int32
d = 0;
d < dim; ++
d) {
120 ko.
Stream() << ss.str().c_str();
124 num_done ++; num_utt ++;
127 KALDI_LOG <<
"Converted " << num_done <<
" alignments to pfiles.";
128 KALDI_LOG << num_no_ali <<
" utterances have no alignment; " 129 << num_other_error <<
" utterances have other errors.";
130 }
catch(
const std::exception& e) {
131 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].
int32 TransitionIdToPdf(int32 trans_id) const
void Register(const std::string &name, bool *ptr, const std::string &doc)
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)
void Read(std::istream &is, bool binary)
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)
int NumArgs() const
Number of positional parameters (c.f. argc-1).
#define KALDI_ASSERT(cond)
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
void Read(std::istream &in_stream, bool binary)
int main(int argc, char *argv[])
Build pfiles for Neural Network training from alignment.