static int acmod_init_am(acmod_t *acmod) { char const *mdeffn, *tmatfn; /* Read model definition. */ if ((mdeffn = cmd_ln_str_r(acmod->config, "-mdef")) == NULL) { E_ERROR("Must specify -mdef or -hmm\n"); return -1; } if ((acmod->mdef = bin_mdef_read(acmod->config, mdeffn)) == NULL) { E_ERROR("Failed to read model definition from %s\n", mdeffn); return -1; } /* Read transition matrices. */ if ((tmatfn = cmd_ln_str_r(acmod->config, "-tmat")) == NULL) { E_ERROR("No tmat file specified\n"); return -1; } acmod->tmat = tmat_init(tmatfn, acmod->lmath, cmd_ln_float32_r(acmod->config, "-tmatfloor"), TRUE); /* Read the acoustic models. */ if ((cmd_ln_str_r(acmod->config, "-mean") == NULL) || (cmd_ln_str_r(acmod->config, "-var") == NULL) || (cmd_ln_str_r(acmod->config, "-tmat") == NULL)) { E_ERROR("No mean/var/tmat files specified\n"); return -1; } if (cmd_ln_str_r(acmod->config, "-senmgau")) { E_INFO("Using general multi-stream GMM computation\n"); acmod->mgau = ms_mgau_init(acmod->config, acmod->lmath, acmod->mdef); if (acmod->mgau == NULL) return -1; } else { E_INFO("Attempting to use SCHMM computation module\n"); if ((acmod->mgau = s2_semi_mgau_init(acmod)) == NULL) { E_INFO("Attempting to use PTHMM computation module\n"); if ((acmod->mgau = ptm_mgau_init(acmod)) == NULL) { E_INFO("Falling back to general multi-stream GMM computation\n"); acmod->mgau = ms_mgau_init(acmod->config, acmod->lmath, acmod->mdef); if (acmod->mgau == NULL) return -1; } } } return 0; }
int main(int argc, char *argv[]) { logmath_t *lmath; cmd_ln_t *config; acmod_t *acmod; ps_mgau_t *ps; ptm_mgau_t *s; int i, lastcb; lmath = logmath_init(1.0001, 0, 0); config = cmd_ln_init(NULL, ps_args(), TRUE, "-compallsen", "yes", "-input_endian", "little", NULL); cmd_ln_parse_file_r(config, ps_args(), MODELDIR "/en-us/en-us/feat.params", FALSE); cmd_ln_set_str_extra_r(config, "_mdef", MODELDIR "/en-us/en-us/mdef"); cmd_ln_set_str_extra_r(config, "_mean", MODELDIR "/en-us/en-us/means"); cmd_ln_set_str_extra_r(config, "_var", MODELDIR "/en-us/en-us/variances"); cmd_ln_set_str_extra_r(config, "_tmat", MODELDIR "/en-us/en-us/transition_matrices"); cmd_ln_set_str_extra_r(config, "_sendump", MODELDIR "/en-us/en-us/sendump"); cmd_ln_set_str_extra_r(config, "_mixw", NULL); cmd_ln_set_str_extra_r(config, "_lda", NULL); cmd_ln_set_str_extra_r(config, "_senmgau", NULL); err_set_debug_level(3); TEST_ASSERT(config); TEST_ASSERT((acmod = acmod_init(config, lmath, NULL, NULL))); TEST_ASSERT((ps = acmod->mgau)); TEST_EQUAL(0, strcmp(ps->vt->name, "ptm")); s = (ptm_mgau_t *)ps; E_DEBUG(2,("PTM model loaded: %d codebooks, %d senones, %d frames of history\n", s->g->n_mgau, s->n_sen, s->n_fast_hist)); E_DEBUG(2,("Senone to codebook mappings:\n")); lastcb = s->sen2cb[0]; E_DEBUG(2,("\t%d: 0", lastcb)); for (i = 0; i < s->n_sen; ++i) { if (s->sen2cb[i] != lastcb) { lastcb = s->sen2cb[i]; E_DEBUGCONT(2,("-%d\n", i-1)); E_DEBUGCONT(2,("\t%d: %d", lastcb, i)); } } E_INFOCONT("-%d\n", i-1); run_acmod_test(acmod); #if 0 /* Replace it with ms_mgau. */ ptm_mgau_free(ps); cmd_ln_set_str_r(config, "-mixw", MODELDIR "/en-us/en-us/mixture_weights"); TEST_ASSERT((acmod->mgau = ms_mgau_init(acmod, lmath, acmod->mdef))); run_acmod_test(acmod); cmd_ln_free_r(config); #endif return 0; }
static int acmod_init_am(acmod_t *acmod) { char const *mdeffn, *tmatfn, *mllrfn, *hmmdir; /* Read model definition. */ if ((mdeffn = cmd_ln_str_r(acmod->config, "-mdef")) == NULL) { if ((hmmdir = cmd_ln_str_r(acmod->config, "-hmm")) == NULL) E_ERROR("Acoustic model definition is not specified either " "with -mdef option or with -hmm\n"); else E_ERROR("Folder '%s' does not contain acoustic model " "definition 'mdef'\n", hmmdir); return -1; } if ((acmod->mdef = bin_mdef_read(acmod->config, mdeffn)) == NULL) { E_ERROR("Failed to read acoustic model definition from %s\n", mdeffn); return -1; } /* Read transition matrices. */ if ((tmatfn = cmd_ln_str_r(acmod->config, "-tmat")) == NULL) { E_ERROR("No tmat file specified\n"); return -1; } acmod->tmat = tmat_init(tmatfn, acmod->lmath, cmd_ln_float32_r(acmod->config, "-tmatfloor"), TRUE); /* Read the acoustic models. */ if ((cmd_ln_str_r(acmod->config, "-mean") == NULL) || (cmd_ln_str_r(acmod->config, "-var") == NULL) || (cmd_ln_str_r(acmod->config, "-tmat") == NULL)) { E_ERROR("No mean/var/tmat files specified\n"); return -1; } if (cmd_ln_str_r(acmod->config, "-senmgau")) { E_INFO("Using general multi-stream GMM computation\n"); acmod->mgau = ms_mgau_init(acmod, acmod->lmath, acmod->mdef); if (acmod->mgau == NULL) return -1; } else { E_INFO("Attempting to use PTM computation module\n"); if ((acmod->mgau = ptm_mgau_init(acmod, acmod->mdef)) == NULL) { E_INFO("Attempting to use semi-continuous computation module\n"); if ((acmod->mgau = s2_semi_mgau_init(acmod)) == NULL) { E_INFO("Falling back to general multi-stream GMM computation\n"); acmod->mgau = ms_mgau_init(acmod, acmod->lmath, acmod->mdef); if (acmod->mgau == NULL) return -1; } } } /* If there is an MLLR transform, apply it. */ if ((mllrfn = cmd_ln_str_r(acmod->config, "-mllr"))) { ps_mllr_t *mllr = ps_mllr_read(mllrfn); if (mllr == NULL) return -1; acmod_update_mllr(acmod, mllr); } return 0; }