1 #include <pocketsphinx.h>
6 #include "pocketsphinx_internal.h"
7 #include "fsg_search_internal.h"
8 #include "ps_lattice_internal.h"
9 #include "test_macros.h"
12 main(int argc, char *argv[])
24 cmd_ln_init(NULL, ps_args(), TRUE,
25 "-hmm", MODELDIR "/hmm/en_US/hub4wsj_sc_8k",
26 "-fsg", DATADIR "/goforward.fsg",
27 "-dict", MODELDIR "/lm/en/turtle.dic",
29 "-input_endian", "little",
30 "-samprate", "16000", NULL));
31 TEST_ASSERT(ps = ps_init(config));
33 fsgs = (fsg_search_t *)ps->search;
45 TEST_ASSERT(rawfh = fopen(DATADIR "/something.raw", "rb"));
46 TEST_EQUAL(0, acmod_start_utt(acmod));
47 fsg_search_start(ps_search_base(fsgs));
48 while (!feof(rawfh)) {
49 nread = fread(buf, sizeof(*buf), 2048, rawfh);
51 while ((nfr = acmod_process_raw(acmod, &bptr, &nread, FALSE)) > 0) {
52 while (acmod->n_feat_frame > 0) {
53 fsg_search_step(ps_search_base(fsgs),
59 fsg_search_finish(ps_search_base(fsgs));
60 hyp = fsg_search_hyp(ps_search_base(fsgs), &score);
61 printf("FSG: %s (%d)\n", hyp, score);
63 TEST_ASSERT(acmod_end_utt(acmod) >= 0);
66 for (seg = ps_seg_iter(ps, &score); seg;
67 seg = ps_seg_next(seg)) {
70 int32 post, lscr, ascr, lback;
72 word = ps_seg_word(seg);
73 ps_seg_frames(seg, &sf, &ef);
76 post = ps_seg_prob(seg, &ascr, &lscr, &lback);
77 printf("%s (%d:%d) P(w|o) = %f ascr = %d lscr = %d lback = %d\n", word, sf, ef,
78 logmath_exp(ps_get_logmath(ps), post), ascr, lscr, lback);
80 dag = ps_get_lattice(ps);
81 ps_lattice_write(dag, "test_fsg2.lat");
82 link = ps_lattice_bestpath(dag, NULL, 1.0, 1.0/15.0);
83 printf("BESTPATH: %s\n", ps_lattice_hyp(dag, link));
84 ps_lattice_posterior(dag, NULL, 1.0/15.0);
86 printf("%s %d P(w|o) = %d + %d - %d = %d = %f\n",
87 dict_wordstr(ps->dict, link->from->wid),
88 link->ef, link->alpha, link->beta, dag->norm,
89 link->alpha + link->beta - dag->norm,
90 logmath_exp(ps_get_logmath(ps),
91 link->alpha + link->beta - dag->norm));
92 link = link->best_prev;