int mdef_convert_main(int argc, char *argv[]) { const char *infile, *outfile; bin_mdef_t *bin; int tobin = 1; if (argc < 3 || argc > 4) { fprintf(stderr, "Usage: %s [-text | -bin] INPUT OUTPUT\n", argv[0]); return 1; } if (argv[1][0] == '-') { if (strcmp(argv[1], "-text") == 0) { tobin = 0; ++argv; } else if (strcmp(argv[1], "-bin") == 0) { tobin = 1; ++argv; } else { fprintf(stderr, "Unknown argument %s\n", argv[1]); fprintf(stderr, "Usage: %s [-text | -bin] INPUT OUTPUT\n", argv[0]); return 1; } } infile = argv[1]; outfile = argv[2]; if (tobin) { if ((bin = bin_mdef_read_text(NULL, infile)) == NULL) { fprintf(stderr, "Failed to read text mdef from %s\n", infile); return 1; } if (bin_mdef_write(bin, outfile) < 0) { fprintf(stderr, "Failed to write binary mdef to %s\n", outfile); return 1; } } else { if ((bin = bin_mdef_read(NULL, infile)) == NULL) { fprintf(stderr, "Failed to read binary mdef from %s\n", infile); return 1; } if (bin_mdef_write_text(bin, outfile) < 0) { fprintf(stderr, "Failed to write text mdef to %s\n", outfile); return 1; } } return 0; }
int main(int argc, char *argv[]) { bin_mdef_t *mdef; dict_t *dict; cmd_ln_t *config; int i; char buf[100]; TEST_ASSERT(config = cmd_ln_init(NULL, NULL, FALSE, "-dict", MODELDIR "/en-us/cmudict-en-us.dict", "-fdict", MODELDIR "/en-us/en-us/noisedict", NULL)); /* Test dictionary in standard fashion. */ TEST_ASSERT(mdef = bin_mdef_read(NULL, MODELDIR "/en-us/en-us/mdef")); TEST_ASSERT(dict = dict_init(config, mdef, NULL)); printf("Word ID (CARNEGIE) = %d\n", dict_wordid(dict, "CARNEGIE")); printf("Word ID (ASDFASFASSD) = %d\n", dict_wordid(dict, "ASDFASFASSD")); TEST_EQUAL(0, dict_write(dict, "_cmu07a.dic", NULL)); TEST_EQUAL(0, system("diff -uw " MODELDIR "/en-us/cmudict-en-us.dict _cmu07a.dic")); dict_free(dict); bin_mdef_free(mdef); /* Now test an empty dictionary. */ TEST_ASSERT(dict = dict_init(NULL, NULL, NULL)); printf("Word ID(<s>) = %d\n", dict_wordid(dict, "<s>")); TEST_ASSERT(BAD_S3WID != dict_add_word(dict, "FOOBIE", NULL, 0)); TEST_ASSERT(BAD_S3WID != dict_add_word(dict, "BLETCH", NULL, 0)); printf("Word ID(FOOBIE) = %d\n", dict_wordid(dict, "FOOBIE")); printf("Word ID(BLETCH) = %d\n", dict_wordid(dict, "BLETCH")); TEST_ASSERT(dict_real_word(dict, dict_wordid(dict, "FOOBIE"))); TEST_ASSERT(dict_real_word(dict, dict_wordid(dict, "BLETCH"))); TEST_ASSERT(!dict_real_word(dict, dict_wordid(dict, "</s>"))); dict_free(dict); /* Test to add 500k words. */ TEST_ASSERT(dict = dict_init(NULL, NULL, NULL)); for (i = 0; i < 500000; i++) { sprintf(buf, "word_%d", i); TEST_ASSERT(BAD_S3WID != dict_add_word(dict, buf, NULL, 0)); } dict_free(dict); cmd_ln_free_r(config); return 0; }
int main(int argc, char *argv[]) { ngram_trie_t *t; dict_t *dict; bin_mdef_t *mdef; logmath_t *lmath; cmd_ln_t *config; FILE *arpafh; config = cmd_ln_init(NULL, ps_args(), TRUE, "-hmm", TESTDATADIR "/hub4wsj_sc_8k", "-dict", TESTDATADIR "/bn10000.homos.dic", NULL); ps_init_defaults(config); lmath = logmath_init(cmd_ln_float32_r(config, "-logbase"), 0, FALSE); mdef = bin_mdef_read(config, cmd_ln_str_r(config, "-mdef")); dict = dict_init(config, mdef); t = ngram_trie_init(dict, lmath); arpafh = fopen(TESTDATADIR "/bn10000.3g.arpa", "r"); ngram_trie_read_arpa(t, arpafh); fclose(arpafh); /* Test 1, 2, 3-gram probs without backoff. */ test_lookups(t, lmath); arpafh = fopen("tmp.bn10000.3g.arpa", "w"); ngram_trie_write_arpa(t, arpafh); fclose(arpafh); ngram_trie_free(t); t = ngram_trie_init(dict, lmath); arpafh = fopen("tmp.bn10000.3g.arpa", "r"); ngram_trie_read_arpa(t, arpafh); fclose(arpafh); /* Test 1, 2, 3-gram probs without backoff. */ test_lookups(t, lmath); /* Test adding nodes. */ test_add_nodes(t, lmath); ngram_trie_free(t); dict_free(dict); logmath_free(lmath); bin_mdef_free(mdef); cmd_ln_free_r(config); return 0; }
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[]) { bin_mdef_t *mdef; dict_t *dict; dict2pid_t *d2p; cmd_ln_t *config; TEST_ASSERT(config = cmd_ln_init(NULL, NULL, FALSE, "-dict", MODELDIR "/lm/en_US/cmu07a.dic", "-fdict", MODELDIR "/hmm/en_US/hub4wsj_sc_8k/noisedict", NULL)); TEST_ASSERT(mdef = bin_mdef_read(NULL, MODELDIR "/hmm/en_US/hub4wsj_sc_8k/mdef")); TEST_ASSERT(dict = dict_init(config, mdef)); TEST_ASSERT(d2p = dict2pid_build(mdef, dict)); dict_free(dict); dict2pid_free(d2p); bin_mdef_free(mdef); cmd_ln_free_r(config); return 0; }
int main(int argc, char *argv[]) { dict_t *dict; dict2pid_t *d2p; bin_mdef_t *mdef; glextree_t *tree; hmm_context_t *ctx; logmath_t *lmath; tmat_t *tmat; int i; TEST_ASSERT(mdef = bin_mdef_read(NULL, MODELDIR "/hmm/en_US/hub4wsj_sc_8k/mdef")); TEST_ASSERT(dict = dict_init(cmd_ln_init(NULL, NULL, FALSE, "-dict", DATADIR "/turtle.dic", "-dictcase", "no", NULL), mdef)); TEST_ASSERT(d2p = dict2pid_build(mdef, dict)); lmath = logmath_init(1.0001, 0, TRUE); tmat = tmat_init(MODELDIR "/hmm/en_US/hub4wsj_sc_8k/transition_matrices", lmath, 1e-5, TRUE); ctx = hmm_context_init(bin_mdef_n_emit_state(mdef), tmat->tp, NULL, mdef->sseq); TEST_ASSERT(tree = glextree_build(ctx, dict, d2p, NULL, NULL)); /* Check that a path exists for all dictionary words. */ for (i = 0; i < dict_size(dict); ++i) TEST_ASSERT(glextree_has_word(tree, i)); dict_free(dict); dict2pid_free(d2p); bin_mdef_free(mdef); tmat_free(tmat); hmm_context_free(ctx); glextree_free(tree); 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; }