1 #include <pocketsphinx.h>
5 #include "test_macros.h"
8 main(int argc, char *argv[])
14 ngram_model_t *lmset, *lm;
18 /* First decode it with the crappy WSJ language model. */
20 cmd_ln_init(NULL, ps_args(), TRUE,
21 "-hmm", MODELDIR "/hmm/en_US/hub4wsj_sc_8k",
22 "-lm", MODELDIR "/lm/en_US/wsj0vp.5000.DMP",
23 "-dict", DATADIR "/defective.dic",
25 /* FIXME: fwdflat causes some problems. */
26 "-bestpath", "no", "-fwdflat", "no",
27 "-input_endian", "little",
28 "-samprate", "16000", NULL));
29 TEST_ASSERT(ps = ps_init(config));
30 TEST_ASSERT(rawfh = fopen(DATADIR "/goforward.raw", "rb"));
32 ps_decode_raw(ps, rawfh, "goforward", -1);
33 hyp = ps_get_hyp(ps, &score, &uttid);
34 printf("%s: %s (%d)\n", uttid, hyp, score);
35 TEST_EQUAL(0, strcmp(hyp, "go forward ten years"));
37 /* Now load the turtle language model. */
38 lm = ngram_model_read(config,
39 MODELDIR "/lm/en/turtle.DMP",
40 NGRAM_AUTO, ps_get_logmath(ps));
42 lmset = ps_get_lmset(ps);
44 ngram_model_set_add(lmset, lm, "turtle", 1.0, TRUE);
45 ngram_model_set_select(lmset, "turtle");
46 ps_update_lmset(ps, lmset);
48 fseek(rawfh, 0, SEEK_SET);
49 TEST_ASSERT(ps_decode_raw(ps, rawfh, "goforward", -1));
50 hyp = ps_get_hyp(ps, &score, &uttid);
51 printf("%s: %s (%d)\n", uttid, hyp, score);
53 /* Oops! It's still not correct, because METERS isn't in the
54 * dictionary that we originally loaded. */
55 TEST_EQUAL(0, strcmp(hyp, "go forward ten degrees"));
56 /* So let's add it to the dictionary. */
57 ps_add_word(ps, "foobie", "F UW B IY", FALSE);
58 ps_add_word(ps, "meters", "M IY T ER Z", TRUE);
61 fseek(rawfh, 0, SEEK_SET);
62 TEST_ASSERT(ps_decode_raw(ps, rawfh, "goforward", -1));
63 hyp = ps_get_hyp(ps, &score, &uttid);
65 printf("%s: %s (%d)\n", uttid, hyp, score);
66 ps_lattice_write(ps_get_lattice(ps), "meters.lat");
68 TEST_EQUAL(0, strcmp(hyp, "go forward ten meters"));
70 /* Now let's test dictionary switching. */
71 TEST_EQUAL(0, ps_load_dict(ps, MODELDIR "/lm/en/turtle.dic",
75 fseek(rawfh, 0, SEEK_SET);
76 TEST_ASSERT(ps_decode_raw(ps, rawfh, "goforward", -1));
77 hyp = ps_get_hyp(ps, &score, &uttid);
78 printf("%s: %s (%d)\n", uttid, hyp, score);
79 TEST_EQUAL(0, strcmp(hyp, "go forward ten meters"));
81 /* Try switching back again just to make sure. */
82 TEST_EQUAL(0, ps_load_dict(ps, DATADIR "/defective.dic",
85 fseek(rawfh, 0, SEEK_SET);
86 TEST_ASSERT(ps_decode_raw(ps, rawfh, "goforward", -1));
87 hyp = ps_get_hyp(ps, &score, &uttid);
88 printf("%s: %s (%d)\n", uttid, hyp, score);
89 TEST_EQUAL(0, strcmp(hyp, "go forward ten degrees"));