29 int main(
int argc,
char *argv[]) {
30 using namespace kaldi;
34 "Convert alignments from one decision-tree/model to another\n" 35 "Usage: convert-ali [options] <old-model> <new-model> <new-tree> " 36 "<old-alignments-rspecifier> <new-alignments-wspecifier>\n" 38 " convert-ali old/final.mdl new/0.mdl new/tree ark:old/ali.1 ark:new/ali.1\n";
40 int32 frame_subsampling_factor = 1;
42 bool repeat_frames =
false;
44 std::string phone_map_rxfilename;
46 po.
Register(
"phone-map", &phone_map_rxfilename,
47 "File name containing old->new phone mapping (each line is: " 48 "old-integer-id new-integer-id)");
50 "True if you want the converted alignments to be 'reordered' " 51 "versus the way they appear in the HmmTopology object");
52 po.
Register(
"repeat-frames", &repeat_frames,
53 "Only relevant when frame-subsampling-factor != 1. If true, " 54 "repeat frames of alignment by 'frame-subsampling-factor' " 55 "after alignment conversion, to keep the alignment the same " 56 "length as the input alignment.");
57 po.
Register(
"frame-subsampling-factor", &frame_subsampling_factor,
58 "Can be used in converting alignments to reduced frame rates.");
67 std::string old_model_filename = po.
GetArg(1);
68 std::string new_model_filename = po.
GetArg(2);
69 std::string new_tree_filename = po.
GetArg(3);
70 std::string old_alignments_rspecifier = po.
GetArg(4);
71 std::string new_alignments_wspecifier = po.
GetArg(5);
73 std::vector<int32> phone_map;
74 if (phone_map_rxfilename !=
"") {
89 KALDI_WARN <<
"Toplogies of models are not equal: " 90 <<
"conversion may not be correct or may fail.";
96 int num_success = 0, num_fail = 0;
98 for (; !alignment_reader.
Done(); alignment_reader.
Next()) {
99 std::string key = alignment_reader.
Key();
100 const std::vector<int32> &old_alignment = alignment_reader.
Value();
101 std::vector<int32> new_alignment;
106 frame_subsampling_factor,
109 (phone_map_rxfilename !=
"" ? &phone_map : NULL),
111 alignment_writer.
Write(key, new_alignment);
114 KALDI_WARN <<
"Could not convert alignment for key " << key
115 <<
" (possibly truncated alignment?)";
120 KALDI_LOG <<
"Succeeded converting alignments for " << num_success
121 <<
" files, failed for " << num_fail;
123 if (num_success != 0)
return 0;
125 }
catch(
const std::exception &e) {
126 std::cerr << e.what();
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
void PrintUsage(bool print_command_line=false)
Prints the usage documentation [provided in the constructor].
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)
void ReadKaldiObject(const std::string &filename, Matrix< float > *m)
void ReadPhoneMap(std::string phone_map_rxfilename, std::vector< int32 > *phone_map)
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
const HmmTopology & GetTopo() const
return reference to HMM-topology object.
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).
bool ConvertAlignment(const TransitionModel &old_trans_model, const TransitionModel &new_trans_model, const ContextDependencyInterface &new_ctx_dep, const std::vector< int32 > &old_alignment, int32 subsample_factor, bool repeat_frames, bool new_is_reordered, const std::vector< int32 > *phone_map, std::vector< int32 > *new_alignment)
ConvertAlignment converts an alignment that was created using one model, to another model...
int main(int argc, char *argv[])