00001
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef __SENT_HTK_HMM_2_H__
00029 #define __SENT_HTK_HMM_2_H__
00030
00031 #include <sent/stddefs.h>
00032 #include <sent/htk_defs.h>
00033 #include <sent/ptree.h>
00034
00036 #define currentis(A) (!strcasecmp(A, rdhmmdef_token))
00037
00038 #define NoTokErr(S) if (!rdhmmdef_token) rderr(S)
00039
00041 #define HMMDEF_DELM " \t\n<>"
00042
00043
00067
00068
00070 #define MAX_STATE_NUM 65535
00071
00073 #define HMM_RC_DLIM "+"
00074 #define HMM_LC_DLIM "-"
00075 #define HMM_RC_DLIM_C '+'
00076 #define HMM_LC_DLIM_C '-'
00077
00078
00079 #define SPMODEL_NAME_DEFAULT "sp"
00080
00082 #define MAX_HMMNAME_LEN 128
00083
00085 enum iwcd_type {
00086 IWCD_MAX,
00087 IWCD_AVG,
00088 IWCD_NBEST
00089 };
00090
00091
00092
00093
00095 typedef struct {
00096 short num;
00097 short vsize[50];
00098 } HTK_HMM_StreamInfo;
00099
00101 typedef struct {
00102 HTK_HMM_StreamInfo stream_info;
00103 short vec_size;
00104 short cov_type;
00105 short dur_type;
00106 short param_type;
00107 } HTK_HMM_Options;
00108
00109
00111 typedef struct _HTK_HMM_trans {
00112 char *name;
00113 short statenum;
00114 PROB **a;
00115 struct _HTK_HMM_trans *next;
00116 } HTK_HMM_Trans;
00117
00119 typedef struct _HTK_HMM_variance {
00120 char *name;
00121 VECT *vec;
00122 short len;
00123 struct _HTK_HMM_variance *next;
00124 } HTK_HMM_Var;
00125
00127 typedef struct _HTK_HMM_dens {
00128 char *name;
00129 VECT *mean;
00130 short meanlen;
00131 HTK_HMM_Var *var;
00132
00136 LOGPROB gconst;
00137 struct _HTK_HMM_dens *next;
00138 } HTK_HMM_Dens;
00139
00147 typedef struct _HTK_HMM_state {
00148 char *name;
00149 short mix_num;
00150 HTK_HMM_Dens **b;
00151 PROB *bweight;
00152 unsigned short id;
00153 struct _HTK_HMM_state *next;
00154 } HTK_HMM_State;
00155
00157 typedef struct _HTK_HMM_data {
00158 char *name;
00159 short state_num;
00160 HTK_HMM_State **s;
00161 HTK_HMM_Trans *tr;
00162 struct _HTK_HMM_data *next;
00163 } HTK_HMM_Data;
00164
00166 typedef struct {
00167 char *name;
00168 int num;
00169 HTK_HMM_Dens **d;
00170 unsigned short id;
00171 } GCODEBOOK;
00173
00175 typedef struct {
00176 HTK_HMM_State *state;
00177
00178 } GS_SET;
00179
00180
00223
00224
00226 typedef struct {
00227 HTK_HMM_State **s;
00228 unsigned short num;
00229 unsigned short maxnum;
00230 } CD_State_Set;
00238 typedef struct _cd_set{
00239 char *name;
00240 CD_State_Set *stateset;
00241 unsigned short state_num;
00242 HTK_HMM_Trans *tr;
00243 struct _cd_set *next;
00244 } CD_Set;
00246 typedef struct {
00247 APATNODE *cdtree;
00248 } HMM_CDSET_INFO;
00250
00251
00274 typedef struct _HMM_logical {
00275 char *name;
00276 boolean is_pseudo;
00277
00278 union {
00279 HTK_HMM_Data *defined;
00280 CD_Set *pseudo;
00281 } body;
00282 struct _HMM_logical *next;
00283 } HMM_Logical;
00284
00290 typedef struct {
00291 char *name;
00292 boolean bgnflag;
00293 boolean endflag;
00294 } BASEPHONE;
00300 typedef struct {
00301 int num;
00302 int bgnnum;
00303 int endnum;
00304 APATNODE *root;
00305 } HMM_basephone;
00306
00312 typedef struct {
00317 HTK_HMM_Options opt;
00318 HTK_HMM_Trans *trstart;
00319 HTK_HMM_Var *vrstart;
00320 HTK_HMM_Dens *dnstart;
00321 HTK_HMM_State *ststart;
00322 HTK_HMM_Data *start;
00323
00324
00329 HMM_Logical *lgstart;
00330
00331
00336 APATNODE *tr_root;
00337 APATNODE *vr_root;
00338 APATNODE *dn_root;
00339 APATNODE *st_root;
00340 APATNODE *physical_root;
00341 APATNODE *logical_root;
00342 APATNODE *codebook_root;
00343
00344
00349 HMM_basephone basephone;
00350 HMM_CDSET_INFO cdset_info;
00351
00352
00357 boolean is_triphone;
00358 boolean is_tied_mixture;
00359 short cdset_method;
00360 short cdmax_num;
00361 HMM_Logical *sp;
00362 #ifdef MULTIPATH_VERSION
00363 LOGPROB iwsp_penalty;
00364 #endif
00365
00366 int totalmixnum;
00367 int totalstatenum;
00368 int totalhmmnum;
00369 int totallogicalnum;
00370 int totalpseudonum;
00371 int codebooknum;
00372 int maxcodebooksize;
00373 int maxmixturenum;
00374 int maxstatenum;
00375
00376 } HTK_HMM_INFO;
00377
00378
00379
00380
00381 void htk_hmm_set_pause_model(HTK_HMM_INFO *hmminfo, char *spmodel_name);
00382
00383 void rderr(char *str);
00384 char *read_token(FILE *fp);
00385 void init_hmm(HTK_HMM_INFO *);
00386 boolean rdhmmdef(FILE *, HTK_HMM_INFO *);
00387
00388 void set_global_opt(FILE *fp, HTK_HMM_INFO *hmm);
00389 char *get_cov_str(short covtype);
00390 char *get_dur_str(short durtype);
00391
00392 void trans_add(HTK_HMM_INFO *hmm, HTK_HMM_Trans *new);
00393 HTK_HMM_Trans *get_trans_data(FILE *, HTK_HMM_INFO *);
00394 void def_trans_macro(char *, FILE *, HTK_HMM_INFO *);
00395
00396 HTK_HMM_State *get_state_data(FILE *, HTK_HMM_INFO *);
00397 void def_state_macro(char *, FILE *, HTK_HMM_INFO *);
00398 HTK_HMM_State *state_lookup(HTK_HMM_INFO *hmm, char *keyname);
00399 void state_add(HTK_HMM_INFO *hmm, HTK_HMM_State *new);
00400
00401 HTK_HMM_Dens *get_dens_data(FILE *, HTK_HMM_INFO *);
00402 void def_dens_macro(char *, FILE *, HTK_HMM_INFO *);
00403 HTK_HMM_Dens *dens_lookup(HTK_HMM_INFO *hmm, char *keyname);
00404 void dens_add(HTK_HMM_INFO *hmm, HTK_HMM_Dens *new);
00405
00406 HTK_HMM_Var *get_var_data(FILE *, HTK_HMM_INFO *);
00407 void def_var_macro(char *, FILE *, HTK_HMM_INFO *);
00408 void var_add(HTK_HMM_INFO *hmm, HTK_HMM_Var *new);
00409
00410 void def_HMM(char *, FILE *, HTK_HMM_INFO *);
00411 HTK_HMM_Data *htk_hmmdata_new();
00412 void htk_hmmdata_add(HTK_HMM_INFO *hmm, HTK_HMM_Data *new);
00413
00414 void tmix_read(FILE *fp, HTK_HMM_State *state, HTK_HMM_INFO *hmm);
00415 void codebook_add(HTK_HMM_INFO *hmm, GCODEBOOK *new);
00416
00417 void def_regtree_macro(char *name, FILE *fp, HTK_HMM_INFO *hmm);
00418
00419 boolean rdhmmlist(FILE *fp, HTK_HMM_INFO *hmminfo);
00420
00421 void put_htk_trans(HTK_HMM_Trans *t);
00422 void put_htk_var(HTK_HMM_Var *v);
00423 void put_htk_dens(HTK_HMM_Dens *d);
00424 void put_htk_state(HTK_HMM_State *s);
00425 void put_htk_hmm(HTK_HMM_Data *h);
00426 void put_logical_hmm(HMM_Logical *l);
00427 void print_hmmdef_info(HTK_HMM_INFO *);
00428 HTK_HMM_INFO *hmminfo_new();
00429 void init_hmminfo(HTK_HMM_INFO *hmminfo, char *filename, char *mapfile);
00430 HTK_HMM_Data *htk_hmmdata_lookup_physical(HTK_HMM_INFO *, char *);
00431 HMM_Logical *htk_hmmdata_lookup_logical(HTK_HMM_INFO *, char *);
00432 void hmm_add_physical_to_logical(HTK_HMM_INFO *);
00433 void hmm_add_pseudo_phones(HTK_HMM_INFO *hmminfo);
00434
00435 void make_hmm_basephone_list(HTK_HMM_INFO *hmminfo);
00436
00437
00438 boolean check_hmm_limit(HTK_HMM_Data *dt);
00439 boolean check_all_hmm_limit(HTK_HMM_INFO *hmm);
00440 boolean check_hmm_options(HTK_HMM_INFO *hmm);
00441 #ifdef MULTIPATH_VERSION
00442 boolean is_skippable_model(HTK_HMM_Data *d);
00443 #endif
00444
00445
00446 boolean guess_if_cd_hmm(HTK_HMM_INFO *hmm);
00447 HMM_Logical *get_right_context_HMM(HMM_Logical *base, char *rc_name, HTK_HMM_INFO *hmminfo);
00448 HMM_Logical *get_left_context_HMM(HMM_Logical *base, char *lc_name, HTK_HMM_INFO *hmminfo);
00449 void add_right_context(char name[], char *rc);
00450 void add_left_context(char name[], char *lc);
00451 char *center_name(char *hmmname, char *buf);
00452 char *leftcenter_name(char *hmmname, char *buf);
00453 char *rightcenter_name(char *hmmname, char *buf);
00454
00455
00456 boolean regist_cdset(APATNODE **root, HTK_HMM_Data *d, char *cdname);
00457 boolean make_cdset(HTK_HMM_INFO *hmminfo);
00458 void put_all_cdinfo(HTK_HMM_INFO *hmminfo);
00459 CD_Set *cdset_lookup(HTK_HMM_INFO *hmminfo, char *cdstr);
00460 CD_Set *lcdset_lookup_by_hmmname(HTK_HMM_INFO *hmminfo, char *hmmname);
00461 CD_Set *rcdset_lookup_by_hmmname(HTK_HMM_INFO *hmminfo, char *hmmname);
00462 int hmm_logical_state_num(HMM_Logical *lg);
00463 HTK_HMM_Trans *hmm_logical_trans(HMM_Logical *lg);
00464
00465 #include <sent/htk_param.h>
00466 boolean check_param_coherence(HTK_HMM_INFO *hmm, HTK_Param *pinfo);
00467 boolean check_param_basetype(HTK_HMM_INFO *hmm, HTK_Param *pinfo);
00468 HTK_Param *new_param_check_and_adjust(HTK_HMM_INFO *hmm, HTK_Param *pinfo, boolean vflag);
00469
00470
00471
00472 boolean write_binhmm(FILE *fp, HTK_HMM_INFO *hmm);
00473 boolean read_binhmm(FILE *fp, HTK_HMM_INFO *hmm);
00474
00475 #endif