31 using namespace kaldi;
33 using fst::SymbolTable;
38 "Make transducer that de-duplicates context-dependent ilabels that map to the same state\n" 39 "Usage: make-ilabel-transducer ilabel-info-right tree-file transition-gmm/model ilabel-info-left [mapping-fst-out]\n" 41 " make-ilabel-transducer old_ilabel_info 1.tree 1.mdl new_ilabel_info > convert.fst\n";
45 std::string disambig_wxfilename;
46 std::string old2new_map_wxfilename;
47 po.Register(
"write-disambig-syms", &disambig_wxfilename,
"List of disambiguation symbols after the remapping");
48 po.Register(
"old-to-new-mapping", &old2new_map_wxfilename,
"Mapping from old to new symbols (wxfilename)");
49 po.Register(
"binary", &binary,
"Write output ilabels in binary format");
52 if (po.NumArgs() < 4 || po.NumArgs() > 5) {
57 std::string ilabel_info_rxfilename = po.GetArg(1),
58 tree_filename = po.GetArg(2),
59 model_filename = po.GetArg(3),
60 ilabel_info_wxfilename = po.GetArg(4),
61 fst_out_filename = po.GetOptArg(5);
62 if (fst_out_filename ==
"-") fst_out_filename =
"";
64 std::vector<std::vector<int32> > old_ilabels;
67 Input ki(ilabel_info_rxfilename, &binary_in);
78 std::vector<int32> old2new_mapping;
86 if (old2new_map_wxfilename !=
"")
88 KALDI_ERR <<
"Error writing map from old to new symbols to " 91 std::vector<std::vector<int32> > new_ilabels;
93 new_ilabels.resize(1 + *std::max_element(old2new_mapping.begin(),
94 old2new_mapping.end()));
95 for (
size_t old_idx = 0; old_idx < old2new_mapping.size(); old_idx++) {
96 int32 new_idx = old2new_mapping[old_idx];
97 if (new_ilabels[new_idx].empty())
98 new_ilabels[new_idx] = old_ilabels[old_idx];
103 binary, new_ilabels);
106 if (disambig_wxfilename !=
"") {
107 std::vector<int32> new_disambig;
108 for (
size_t new_idx = 0; new_idx < new_ilabels.size(); new_idx++) {
109 if (new_ilabels[new_idx].size() == 1 && new_ilabels[new_idx][0] <= 0) {
110 new_disambig.push_back(new_idx);
114 KALDI_ERR <<
"Could not write disambiguation symbols to " 120 VectorFst<StdArc> map_fst;
124 if (fst_out_filename ==
"")
125 _setmode(_fileno(stdout), _O_BINARY);
128 if (!map_fst.Write(fst_out_filename)) {
129 KALDI_ERR <<
"Error writing output fst to " 130 << (fst_out_filename ==
"" ?
" standard output " 134 }
catch(
const std::exception &e) {
135 std::cerr << e.what();
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
void WriteILabelInfo(std::ostream &os, bool binary, const vector< vector< int32 > > &info)
Utility function for writing ilabel-info vectors to disk.
void GetIlabelMapping(const std::vector< std::vector< int32 > > &ilabel_info_old, const ContextDependencyInterface &ctx_dep, const TransitionModel &trans_model, std::vector< int32 > *old2new_map)
GetIlabelMapping produces a mapping that's similar to HTK's logical-to-physical model mapping (i...
void ReadKaldiObject(const std::string &filename, Matrix< float > *m)
void ReadILabelInfo(std::istream &is, bool binary, vector< vector< int32 > > *info)
Utility function for reading ilabel-info vectors from disk.
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
#define KALDI_ASSERT(cond)
bool WriteIntegerVectorSimple(const std::string &wxfilename, const std::vector< int32 > &list)
WriteToList attempts to write this list of integers, one per line, to the given file, in text format.
std::string PrintableWxfilename(const std::string &wxfilename)
PrintableWxfilename turns the wxfilename into a more human-readable form for error reporting...
void CreateMapFst(const std::vector< I > &symbol_map, MutableFst< Arc > *fst)
CreateMapFst will create an FST representing this symbol_map.