00001
00018
00019
00020
00021
00022
00023
00024
00025 #include "app.h"
00026
00027 extern boolean separate_score_flag;
00028 extern boolean callback_debug_flag;
00029
00031 static char *hookstr[] = {"", "delete", "activate", "deactivate"};
00032
00033 static boolean have_progout = FALSE;
00034
00035
00036 static WORD_ID confword[MAXSEQNUM];
00037 static int confwordnum;
00038
00039 #ifdef CHARACTER_CONVERSION
00040 #define MAXBUFLEN 4096
00041 static char inbuf[MAXBUFLEN];
00042 static char outbuf[MAXBUFLEN];
00043 void
00044 myprintf(char *fmt, ...)
00045 {
00046 va_list ap;
00047 int ret;
00048
00049 va_start(ap,fmt);
00050 ret = vsnprintf(inbuf, MAXBUFLEN, fmt, ap);
00051 va_end(ap);
00052 if (ret > 0) {
00053 printf("%s", charconv(inbuf, outbuf, MAXBUFLEN));
00054 }
00055 }
00056 #else
00057 #define myprintf printf
00058 #endif
00059
00064 #define TEXTWIDTH 70
00065
00071 #define SPTEXTWIDTH 72
00072 #define SPTEXT_FULLWIDTH 76
00073
00074
00075
00076
00088 static void
00089 status_process_online(Recog *recog, void *dummy)
00090 {
00091 if (callback_debug_flag) printf("<ONLINE>\n");
00092 }
00104 static void
00105 status_process_offline(Recog *recog, void *dummy)
00106 {
00107 if (callback_debug_flag) printf("<OFFLINE>\n");
00108 }
00109
00110
00111
00112
00123 static void
00124 status_recready(Recog *recog, void *dummy)
00125 {
00126 if (callback_debug_flag) printf("[SPEECH_READY]\n");
00127 if (recog->jconf->input.speech_input == SP_MIC || recog->jconf->input.speech_input == SP_NETAUDIO) {
00128 if (!recog->process_segment) {
00129 fprintf(stderr, "<<< please speak >>>");
00130 }
00131 }
00132 }
00143 static void
00144 status_recstart(Recog *recog, void *dummy)
00145 {
00146 if (callback_debug_flag) printf("[SPEECH_START]\n");
00147 if (recog->jconf->input.speech_input == SP_MIC || recog->jconf->input.speech_input == SP_NETAUDIO) {
00148 if (!recog->process_segment) {
00149 fprintf(stderr, "\r \r");
00150 }
00151 }
00152 }
00163 static void
00164 status_recend(Recog *recog, void *dummy)
00165 {
00166 if (callback_debug_flag) printf("[SPEECH_STOP]\n");
00167 }
00180 static void
00181 status_param(Recog *recog, void *dummy)
00182 {
00183 if (callback_debug_flag) printf("<STATUS_PARAM>\n");
00184 if (verbose_flag) {
00185
00186 }
00187 }
00188
00189
00190
00191
00205 static void
00206 status_recognition_begin(Recog *recog, void *dummy)
00207 {
00208 if (callback_debug_flag) printf("<RECOGNITION_BEGIN>\n");
00209 if (recog->jconf->decodeopt.segment) {
00210 if (have_progout) {
00211 confwordnum = 0;
00212 }
00213 }
00214 }
00215
00228 static void
00229 status_recognition_end(Recog *recog, void *dummy)
00230 {
00231 if (callback_debug_flag) printf("<RECOGNITION_END>\n");
00232 if (recog->process_segment) {
00233 if (verbose_flag) {
00234 printf("Segmented by short pause, continue to next...\n");
00235 } else {
00236
00237 }
00238 }
00239 if (recog->jconf->decodeopt.segment) {
00240 if (have_progout) {
00241 if (confwordnum > 0) {
00242 printf("\n");
00243 }
00244 }
00245 }
00246 }
00247
00258 static void
00259 status_segment_begin(Recog *recog, void *dummy)
00260 {
00261 if (callback_debug_flag) printf("<SEGMENT_BEGIN>\n");
00262
00263 }
00264
00275 static void
00276 status_segment_end(Recog *recog, void *dummy)
00277 {
00278 if (callback_debug_flag) printf("<SEGMENT_END>\n");
00279 }
00280
00281
00282
00283
00284 static int wst;
00285 static int writelen;
00286
00287
00298 static void
00299 status_pass1_begin(Recog *recog, void *dummy)
00300 {
00301 if (callback_debug_flag) printf("<PASS1_BEGIN>\n");
00302 if (!recog->jconf->decodeopt.realtime_flag) {
00303 VERMES("### Recognition: 1st pass (LR beam)\n");
00304 }
00305
00306 wst = 0;
00307
00308 if (recog->jconf->decodeopt.segment) {
00309 if (have_progout) {
00310 writelen = 0;
00311 }
00312 }
00313
00314 }
00315
00316
00339 static void
00340 result_pass1_current(Recog *recog, void *dummy)
00341 {
00342 int i, j, bgn;
00343 int len, num;
00344 WORD_INFO *winfo;
00345 WORD_ID *seq;
00346 RecogProcess *r;
00347
00348
00349
00350 for(r=recog->process_list;r;r=r->next) {
00351 if (! r->live) continue;
00352 if (! r->have_interim) continue;
00353
00354 winfo = r->lm->winfo;
00355 seq = r->result.pass1.word;
00356 num = r->result.pass1.word_num;
00357
00358
00359 printf("\r");
00360
00361 if (r->config->successive.enabled) {
00362
00363 if (have_progout) {
00364
00365
00366
00367 len = 0;
00368 for(i=0;i<confwordnum;i++) {
00369 if (len + strlen(winfo->woutput[confword[i]]) > SPTEXTWIDTH) {
00370 for(j=len;j<writelen;j++) printf(" ");
00371 printf("\n");
00372 for(j=i;j<confwordnum;j++) confword[j-i] = confword[j];
00373 confwordnum -= i;
00374 len = 0;
00375 i = 0;
00376 writelen = 0;
00377 }
00378 myprintf("%s", winfo->woutput[confword[i]]);
00379 len += strlen(winfo->woutput[confword[i]]);
00380 }
00381
00382
00383 if (!r->pass1.first_sparea) {
00384 printf("|");
00385 len++;
00386
00387 if (confword[confwordnum-1] == seq[0]) {
00388 bgn = 1;
00389 } else {
00390 bgn = 0;
00391 }
00392
00393 for(i=bgn;i<num;i++) {
00394 if (len + strlen(winfo->woutput[seq[i]]) > SPTEXT_FULLWIDTH) {
00395 if (i < num - 1) continue;
00396 myprintf("*");
00397 len += 1;
00398 } else {
00399 myprintf("%s", winfo->woutput[seq[i]]);
00400 len += strlen(winfo->woutput[seq[i]]);
00401 }
00402 }
00403 printf("|");
00404 len++;
00405 }
00406
00407 fflush(stdout);
00408
00409 if (writelen < len) writelen = len;
00410
00411 return;
00412 }
00413 }
00414
00415 len = 0;
00416 if (wst == 0) {
00417 len += 11;
00418 printf("pass1_best:");
00419 }
00420
00421 bgn = wst;
00422 for (i=bgn;i<num;i++) {
00423 len += strlen(winfo->woutput[seq[i]]) + 1;
00424 if (len > FILLWIDTH) {
00425 wst = i;
00426 printf("\n");
00427 len = 0;
00428 }
00429 myprintf(" %s",winfo->woutput[seq[i]]);
00430 }
00431 if (writelen < len) writelen = len;
00432
00433 }
00434
00435 fflush(stdout);
00436 }
00437
00438 static void
00439 result_pass1_determined(Recog *recog, void *dummy)
00440 {
00441 RecogProcess *r;
00442
00443 for(r=recog->process_list;r;r=r->next) {
00444 if (! r->live) continue;
00445 if (! r->determined) continue;
00446 printf("#%d %s: determined at %d: %s\n", r->config->id, r->config->name, r->result.num_frame, r->lm->winfo->woutput[r->result.pass1.word[0]]);
00447 }
00448 }
00449
00450
00451
00475 static void
00476 result_pass1(Recog *recog, void *dummy)
00477 {
00478 int i,j;
00479 static char buf[MAX_HMMNAME_LEN];
00480 WORD_INFO *winfo;
00481 WORD_ID *seq;
00482 int num;
00483 RecogProcess *r;
00484 boolean multi;
00485 int len;
00486
00487 if (callback_debug_flag) printf("<RESULT_PASS1>\n");
00488
00489 if (recog->process_list->next != NULL) multi = TRUE;
00490 else multi = FALSE;
00491
00492 for(r=recog->process_list;r;r=r->next) {
00493 if (! r->live) continue;
00494 if (r->result.status < 0) continue;
00495 if (have_progout && r->config->successive.enabled) continue;
00496 if (r->config->output.progout_flag) printf("\r");
00497
00498 winfo = r->lm->winfo;
00499 seq = r->result.pass1.word;
00500 num = r->result.pass1.word_num;
00501
00502
00503 if (multi) printf("[#%d %s]\n", r->config->id, r->config->name);
00504 printf("pass1_best:");
00505 if (r->config->output.progout_flag) {
00506 len = 0;
00507 for (i=0;i<num;i++) {
00508 len += strlen(winfo->woutput[seq[i]]) + 1;
00509 myprintf(" %s",winfo->woutput[seq[i]]);
00510 }
00511 for(j=len;j<writelen;j++) printf(" ");
00512 } else {
00513 for (i=0;i<num;i++) {
00514 myprintf(" %s",winfo->woutput[seq[i]]);
00515 }
00516 }
00517 printf("\n");
00518
00519 if (verbose_flag) {
00520
00521 printf("pass1_best_wordseq:");
00522 for (i=0;i<num;i++) {
00523 myprintf(" %s",winfo->wname[seq[i]]);
00524 }
00525 printf("\n");
00526
00527 printf("pass1_best_phonemeseq:");
00528 for (i=0;i<num;i++) {
00529 for (j=0;j<winfo->wlen[seq[i]];j++) {
00530 center_name(winfo->wseq[seq[i]][j]->name, buf);
00531 myprintf(" %s", buf);
00532 }
00533 if (i < num-1) printf(" |");
00534 }
00535 printf("\n");
00536 if (debug2_flag) {
00537
00538 printf("pass1_best_HMMseq_logical:");
00539 for (i=0;i<num;i++) {
00540 for (j=0;j<winfo->wlen[seq[i]];j++) {
00541 myprintf(" %s", winfo->wseq[seq[i]][j]->name);
00542 }
00543 if (i < num-1) printf(" |");
00544 }
00545 printf("\n");
00546 }
00547
00548 printf("pass1_best_score: %f", r->result.pass1.score);
00549 if (r->lmtype == LM_PROB) {
00550 if (separate_score_flag) {
00551 printf(" (AM: %f LM: %f)",
00552 r->result.pass1.score_am,
00553 r->result.pass1.score_lm);
00554 }
00555 }
00556 printf("\n");
00557 }
00558
00559 }
00560 }
00561
00562 #ifdef WORD_GRAPH
00563 static void
00564 result_pass1_graph(Recog *recog, void *dummy)
00565 {
00566 WordGraph *wg;
00567 WORD_INFO *winfo;
00568 RecogProcess *r;
00569 boolean multi;
00570 int n;
00571 int tw1, tw2, i;
00572
00573 if (callback_debug_flag) printf("<RESULT_GRAPH_PASS1>\n");
00574
00575 if (recog->process_list->next != NULL) multi = TRUE;
00576 else multi = FALSE;
00577
00578 for(r=recog->process_list;r;r=r->next) {
00579 if (! r->live) continue;
00580 if (r->result.wg1 == NULL) continue;
00581 if (multi) printf("[#%d %s]\n", r->config->id, r->config->name);
00582 printf("--- begin wordgraph data pass1 ---\n");
00583
00584 winfo = r->lm->winfo;
00585
00586 wordgraph_dump(stdout, r->result.wg1, winfo);
00587 for(wg=r->result.wg1;wg;wg=wg->next) {
00588 tw1 = (TEXTWIDTH * wg->lefttime) / recog->peseqlen;
00589 tw2 = (TEXTWIDTH * wg->righttime) / recog->peseqlen;
00590 printf("%4d:", wg->id);
00591 for(i=0;i<tw1;i++) printf(" ");
00592 myprintf(" %s\n", winfo->woutput[wg->wid]);
00593 printf("%4d:", wg->lefttime);
00594 for(i=0;i<tw1;i++) printf(" ");
00595 printf("|");
00596 for(i=tw1+1;i<tw2;i++) printf("-");
00597 printf("|\n");
00598 }
00599 printf("--- end wordgraph data pass1 ---\n");
00600
00601 }
00602 }
00603
00604 #endif
00605
00616 static void
00617 status_pass1_end(Recog *recog, void *dummy)
00618 {
00619 if (callback_debug_flag) printf("<PASS1_END>\n");
00620 if (recog->jconf->decodeopt.segment) {
00621 if (have_progout) return;
00622 }
00623
00624
00625 }
00626
00627
00628
00629
00644 static void
00645 put_hypo_woutput(WORD_ID *seq, int n, WORD_INFO *winfo)
00646 {
00647 int i;
00648
00649 if (seq != NULL) {
00650 for (i=0;i<n;i++) {
00651 myprintf(" %s",winfo->woutput[seq[i]]);
00652 }
00653 }
00654 printf("\n");
00655 }
00656
00671 static void
00672 put_hypo_wname(WORD_ID *seq, int n, WORD_INFO *winfo)
00673 {
00674 int i;
00675
00676 if (seq != NULL) {
00677 for (i=0;i<n;i++) {
00678 myprintf(" %s",winfo->wname[seq[i]]);
00679 }
00680 }
00681 printf("\n");
00682 }
00683
00698 static void
00699 put_hypo_phoneme(WORD_ID *seq, int n, WORD_INFO *winfo)
00700 {
00701 int i,j;
00702 WORD_ID w;
00703 static char buf[MAX_HMMNAME_LEN];
00704
00705 if (seq != NULL) {
00706 for (i=0;i<n;i++) {
00707 if (i > 0) printf(" |");
00708 w = seq[i];
00709 for (j=0;j<winfo->wlen[w];j++) {
00710 center_name(winfo->wseq[w][j]->name, buf);
00711 myprintf(" %s", buf);
00712 }
00713 }
00714 }
00715 printf("\n");
00716 }
00717 #ifdef CONFIDENCE_MEASURE
00718
00730 #ifdef CM_MULTIPLE_ALPHA
00731 static void
00732 put_hypo_cmscore(NODE *hypo, int id)
00733 {
00734 int i;
00735 int j;
00736
00737 if (hypo != NULL) {
00738 for (i=hypo->seqnum-1;i>=0;i--) {
00739 printf(" %5.3f", hypo->cmscore[i][id]);
00740 }
00741 }
00742 printf("\n");
00743 }
00744 #else
00745 static void
00746 put_hypo_cmscore(LOGPROB *cmscore, int n)
00747 {
00748 int i;
00749
00750 if (cmscore != NULL) {
00751 for (i=0;i<n;i++) {
00752 printf(" %5.3f", cmscore[i]);
00753 }
00754 }
00755 printf("\n");
00756 }
00757 #endif
00758 #endif
00759
00776 static void
00777
00778 result_pass2(Recog *recog, void *dummy)
00779 {
00780 int i, j;
00781 int len;
00782 char ec[5] = {0x1b, '[', '1', 'm', 0};
00783 WORD_INFO *winfo;
00784 WORD_ID *seq;
00785 int seqnum;
00786 int n, num;
00787 Sentence *s;
00788 RecogProcess *r;
00789 boolean multi;
00790
00791 if (callback_debug_flag) printf("<RESULT_PASS2>\n");
00792
00793 if (recog->process_list->next != NULL) multi = TRUE;
00794 else multi = FALSE;
00795
00796 for(r=recog->process_list;r;r=r->next) {
00797 if (! r->live) continue;
00798 if (multi) printf("[#%d %s]\n", r->config->id, r->config->name);
00799
00800 if (r->config->successive.enabled) {
00801 if (r->result.status < 0 && r->config->output.progout_flag) {
00802
00803
00804 printf("\r");
00805 winfo = r->lm->winfo;
00806
00807 if (r->result.status == J_RESULT_STATUS_FAIL) {
00808
00809
00810 seq = r->result.pass1.word;
00811 seqnum = r->result.pass1.word_num;
00812 j = 0;
00813
00814 if (confword[confwordnum-1] == seq[0]) j++;
00815
00816
00817 for (i=j;i<seqnum;i++) {
00818 confword[confwordnum++] = seq[i];
00819 }
00820 }
00821
00822 len = 0;
00823
00824 for(i=0;i<confwordnum;i++) {
00825 if (len + strlen(winfo->woutput[confword[i]]) > SPTEXTWIDTH) {
00826 for(j=len;j<writelen;j++) printf(" ");
00827 printf("\n");
00828 for(j=i;j<confwordnum;j++) confword[j-i] = confword[j];
00829 confwordnum -= i;
00830 len = 0;
00831 i = 0;
00832 writelen = 0;
00833 }
00834 myprintf("%s", winfo->woutput[confword[i]]);
00835 len += strlen(winfo->woutput[confword[i]]);
00836 }
00837 for(i=len;i<writelen;i++) printf(" ");
00838 fflush(stdout);
00839
00840 continue;
00841 }
00842 }
00843
00844 if (r->result.status < 0) {
00845 switch(r->result.status) {
00846 case J_RESULT_STATUS_REJECT_POWER:
00847 printf("<input rejected by power>\n");
00848 break;
00849 case J_RESULT_STATUS_TERMINATE:
00850 printf("<input teminated by request>\n");
00851 break;
00852 case J_RESULT_STATUS_ONLY_SILENCE:
00853 printf("<input rejected by decoder (silence input result)>\n");
00854 break;
00855 case J_RESULT_STATUS_REJECT_GMM:
00856 printf("<input rejected by GMM>\n");
00857 break;
00858 case J_RESULT_STATUS_REJECT_SHORT:
00859 printf("<input rejected by short input>\n");
00860 break;
00861 case J_RESULT_STATUS_FAIL:
00862 printf("<search failed>\n");
00863 break;
00864 }
00865 continue;
00866 }
00867
00868 winfo = r->lm->winfo;
00869 num = r->result.sentnum;
00870
00871 for(n=0;n<num;n++) {
00872 s = &(r->result.sent[n]);
00873 seq = s->word;
00874 seqnum = s->word_num;
00875
00876 if (r->config->successive.enabled) {
00877 if (r->config->output.progout_flag) {
00878 printf("\r");
00879
00880 j = 0;
00881
00882 if (confword[confwordnum-1] == seq[0]) j++;
00883 for (i=j;i<seqnum;i++) {
00884 confword[confwordnum++] = seq[i];
00885 }
00886
00887
00888 len = 0;
00889 for(i=0;i<confwordnum;i++) {
00890 if (len + strlen(winfo->woutput[confword[i]]) > SPTEXTWIDTH) {
00891 for(j=len;j<writelen;j++) printf(" ");
00892 printf("\n");
00893 for(j=i;j<confwordnum;j++) confword[j-i] = confword[j];
00894 confwordnum -= i;
00895 len = 0;
00896 i = 0;
00897 writelen = 0;
00898 }
00899 myprintf("%s", winfo->woutput[confword[i]]);
00900 len += strlen(winfo->woutput[confword[i]]);
00901 }
00902 for(i=len;i<writelen;i++) printf(" ");
00903
00904 break;
00905 }
00906 }
00907
00908 if (debug2_flag) {
00909 printf("\n%s",ec);
00910 }
00911 printf("sentence%d:", n+1);
00912 put_hypo_woutput(seq, seqnum, winfo);
00913 if (verbose_flag) {
00914 printf("wseq%d:", n+1);
00915 put_hypo_wname(seq, seqnum, winfo);
00916 printf("phseq%d:", n+1);
00917 put_hypo_phoneme(seq, seqnum, winfo);
00918 #ifdef CONFIDENCE_MEASURE
00919 #ifdef CM_MULTIPLE_ALPHA
00920 {
00921 int i;
00922 for(i=0;i<r->config->annotate.cm_alpha_num;i++) {
00923 printf("cmscore%d[%f]:", rank, r->config->annotate.cm_alpha_bgn + i * r->config->annotate.cm_alpha_step);
00924 put_hypo_cmscore(hypo, i);
00925 }
00926 }
00927 #else
00928 printf("cmscore%d:", n+1);
00929 put_hypo_cmscore(s->confidence, seqnum);
00930 #endif
00931 #endif
00932 }
00933 if (debug2_flag) {
00934 ec[2] = '0';
00935 printf("%s\n",ec);
00936 }
00937 if (verbose_flag) {
00938 printf("score%d: %f", n+1, s->score);
00939 if (r->lmtype == LM_PROB) {
00940 if (separate_score_flag) {
00941 printf(" (AM: %f LM: %f)", s->score_am, s->score_lm);
00942 }
00943 }
00944 printf("\n");
00945 if (r->lmtype == LM_DFA) {
00946
00947
00948 if (multigram_get_all_num(r->lm) > 1) {
00949 printf("grammar%d: %d\n", n+1, s->gram_id);
00950 }
00951 }
00952 }
00953
00954
00955 if (s->align.filled) {
00956 HMM_Logical *p;
00957 int i;
00958
00959 printf("=== begin forced alignment ===\n");
00960 printf(" id: from to n_score unit\n");
00961 printf(" ----------------------------------------\n");
00962 for(i=0;i<s->align.num;i++) {
00963 printf("[%4d %4d] %f ", s->align.begin_frame[i], s->align.end_frame[i], s->align.avgscore[i]);
00964 switch(s->align.unittype) {
00965 case PER_WORD:
00966 myprintf("%s\t[%s]\n", winfo->wname[s->align.w[i]], winfo->woutput[s->align.w[i]]);
00967 break;
00968 case PER_PHONEME:
00969 p = s->align.ph[i];
00970 if (p->is_pseudo) {
00971 printf("{%s}\n", p->name);
00972 } else if (strmatch(p->name, p->body.defined->name)) {
00973 printf("%s\n", p->name);
00974 } else {
00975 printf("%s[%s]\n", p->name, p->body.defined->name);
00976 }
00977 break;
00978 case PER_STATE:
00979 p = s->align.ph[i];
00980 if (p->is_pseudo) {
00981 printf("{%s}", p->name);
00982 } else if (strmatch(p->name, p->body.defined->name)) {
00983 printf("%s", p->name);
00984 } else {
00985 printf("%s[%s]", p->name, p->body.defined->name);
00986 }
00987 if (r->am->hmminfo->multipath) {
00988 if (s->align.is_iwsp[i]) {
00989 printf(" #%d (sp)\n", s->align.loc[i]);
00990 } else {
00991 printf(" #%d\n", s->align.loc[i]);
00992 }
00993 } else {
00994 printf(" #%d\n", s->align.loc[i]);
00995 }
00996 break;
00997 }
00998 }
00999
01000 printf("re-computed AM score: %f\n", s->align.allscore);
01001
01002 printf("=== end forced alignment ===\n");
01003 }
01004 }
01005 }
01006
01007 fflush(stdout);
01008
01009 }
01010
01023 static void
01024 status_pass2_begin(Recog *recog, void *dummy)
01025 {
01026 if (callback_debug_flag) printf("<PASS2_BEGIN>\n");
01027
01028 VERMES("### Recognition: 2nd pass (RL heuristic best-first)\n");
01029
01030
01031 }
01032
01043 static void
01044 status_pass2_end(Recog *recog, void *dummy)
01045 {
01046 if (callback_debug_flag) printf("<PASS2_END>\n");
01047
01048 fflush(stdout);
01049 }
01050
01051
01052
01053
01054 #define TEXTWIDTH 70
01055
01070 static void
01071 result_graph(Recog *recog, void *dummy)
01072 {
01073 WordGraph *wg;
01074 int tw1, tw2, i;
01075 WORD_INFO *winfo;
01076 RecogProcess *r;
01077 boolean multi;
01078
01079 if (callback_debug_flag) printf("<RESULT_GRAPH>\n");
01080
01081 if (recog->process_list->next != NULL) multi = TRUE;
01082 else multi = FALSE;
01083
01084 for(r=recog->process_list;r;r=r->next) {
01085 if (! r->live) continue;
01086 if (r->result.wg == NULL) continue;
01087 if (multi) printf("[#%d %s]\n", r->config->id, r->config->name);
01088
01089 winfo = r->lm->winfo;
01090
01091
01092 wordgraph_dump(stdout, r->result.wg, winfo);
01093
01094 printf("-------------------------- begin wordgraph show -------------------------\n");
01095 for(wg=r->result.wg;wg;wg=wg->next) {
01096 tw1 = (TEXTWIDTH * wg->lefttime) / r->peseqlen;
01097 tw2 = (TEXTWIDTH * wg->righttime) / r->peseqlen;
01098 printf("%4d:", wg->id);
01099 for(i=0;i<tw1;i++) printf(" ");
01100 myprintf(" %s\n", winfo->woutput[wg->wid]);
01101 printf("%4d:", wg->lefttime);
01102 for(i=0;i<tw1;i++) printf(" ");
01103 printf("|");
01104 for(i=tw1+1;i<tw2;i++) printf("-");
01105 printf("|\n");
01106 }
01107 printf("-------------------------- end wordgraph show ---------------------------\n");
01108 }
01109 }
01110
01121 static void
01122 result_confnet(Recog *recog, void *dummy)
01123 {
01124 CN_CLUSTER *c;
01125 int i;
01126 RecogProcess *r;
01127 boolean multi;
01128
01129 if (callback_debug_flag) printf("<RESULT_CONFNET>\n");
01130 if (recog->process_list->next != NULL) multi = TRUE;
01131 else multi = FALSE;
01132
01133 for(r=recog->process_list;r;r=r->next) {
01134 if (! r->live) continue;
01135 if (r->result.confnet == NULL) continue;
01136 if (multi) printf("[#%d %s]\n", r->config->id, r->config->name);
01137
01138 printf("---- begin confusion network ---\n");
01139 for(c=r->result.confnet;c;c=c->next) {
01140 for(i=0;i<c->wordsnum;i++) {
01141 myprintf("(%s:%.3f)", (c->words[i] == WORD_INVALID) ? "-" : r->lm->winfo->woutput[c->words[i]], c->pp[i]);
01142 if (i == 0) printf(" ");
01143 }
01144 printf("\n");
01145 #if 0
01146
01147 for(i=0;i<c->wgnum;i++) {
01148 printf(" ");
01149 put_wordgraph(stdout, c->wg[i], r->lm->winfo);
01150 }
01151 #endif
01152 }
01153 printf("---- end confusion network ---\n");
01154 }
01155 }
01156
01157
01167 static void
01168 result_gmm(Recog *recog, void *dummy)
01169 {
01170 HTK_HMM_Data *d;
01171 GMMCalc *gc;
01172 int i;
01173
01174 if (callback_debug_flag) printf("<RESULT_GMM>\n");
01175
01176 gc = recog->gc;
01177
01178 if (debug2_flag) {
01179 printf("--- GMM result begin ---\n");
01180 i = 0;
01181 for(d=recog->gmm->start;d;d=d->next) {
01182 myprintf(" [%8s: total=%f avg=%f]\n", d->name, gc->gmm_score[i], gc->gmm_score[i] / (float)gc->framecount);
01183 i++;
01184 }
01185 myprintf(" max = \"%s\"", gc->max_d->name);
01186 #ifdef CONFIDENCE_MEASURE
01187 printf(" (CM: %f)", gc->gmm_max_cm);
01188 #endif
01189 printf("\n");
01190 printf("--- GMM result end ---\n");
01191 } else if (verbose_flag) {
01192 myprintf("GMM: max = \"%s\"", gc->max_d->name);
01193 #ifdef CONFIDENCE_MEASURE
01194 printf(" (CM: %f)", gc->gmm_max_cm);
01195 #endif
01196 printf("\n");
01197 } else {
01198 if (recog->jconf->decodeopt.segment) {
01199 if (!have_progout) {
01200 myprintf("[GMM: %s]\n", gc->max_d->name);
01201 }
01202 } else {
01203 myprintf("[GMM: %s]\n", gc->max_d->name);
01204 }
01205 }
01206 }
01207
01218 void
01219 print_all_gram(Recog *recog)
01220 {
01221 MULTIGRAM *m;
01222 RecogProcess *r;
01223 boolean multi;
01224
01225 if (recog->process_list->next != NULL) multi = TRUE;
01226 else multi = FALSE;
01227
01228 for(r=recog->process_list;r;r=r->next) {
01229 if (! r->live) continue;
01230 if (multi) printf("[#%d %s]\n", r->config->id, r->config->name);
01231
01232 printf("[grammars]\n");
01233 for(m=r->lm->grammars;m;m=m->next) {
01234 printf(" #%2d: [%-11s] %4d words, %3d categories, %4d nodes",
01235 m->id,
01236 m->active ? "active" : "inactive",
01237 m->winfo->num, m->dfa->term_num, m->dfa->state_num);
01238 if (m->newbie) printf(" (new)");
01239 if (m->hook != MULTIGRAM_DEFAULT) {
01240 printf(" (next: %s)", hookstr[m->hook]);
01241 }
01242 myprintf(" \"%s\"\n", m->name);
01243 }
01244 if (r->lm->dfa != NULL) {
01245 printf(" Global: %4d words, %3d categories, %4d nodes\n", r->lm->winfo->num, r->lm->dfa->term_num, r->lm->dfa->state_num);
01246 }
01247 }
01248 }
01249
01250 static void
01251 levelmeter(Recog *recog, SP16 *buf, int len, void *dummy)
01252 {
01253 float d;
01254 int level;
01255 int i, n;
01256
01257 level = 0;
01258 for(i=0;i<len;i++) {
01259 if (level < buf[i]) level = buf[i];
01260 }
01261
01262 d = log((float)(level+1)) / 10.3971466;
01263
01264 n = d * 8.0;
01265 fprintf(stderr, "\r");
01266 for(i=0;i<n;i++) fprintf(stderr, ">");
01267
01268 }
01269
01270
01271 static void
01272 frame_indicator(Recog *recog, void *dummy)
01273 {
01274 RecogProcess *r;
01275
01276 if (recog->jconf->decodeopt.segment) {
01277 for(r=recog->process_list;r;r=r->next) {
01278 if (! r->live) continue;
01279 if (r->pass1.in_sparea) {
01280 fprintf(stderr, ".");
01281 break;
01282 }
01283 }
01284 if (!r) {
01285 fprintf(stderr, "-");
01286 }
01287 } else {
01288 fprintf(stderr, ".");
01289 }
01290 }
01291
01292
01293 void
01294 setup_output_tty(Recog *recog, void *data)
01295 {
01296 callback_add(recog, CALLBACK_EVENT_PROCESS_ONLINE, status_process_online, data);
01297 callback_add(recog, CALLBACK_EVENT_PROCESS_OFFLINE, status_process_offline, data);
01298 callback_add(recog, CALLBACK_EVENT_SPEECH_READY, status_recready, data);
01299 callback_add(recog, CALLBACK_EVENT_SPEECH_START, status_recstart, data);
01300 callback_add(recog, CALLBACK_EVENT_SPEECH_STOP, status_recend, data);
01301 callback_add(recog, CALLBACK_EVENT_RECOGNITION_BEGIN, status_recognition_begin, data);
01302 callback_add(recog, CALLBACK_EVENT_RECOGNITION_END, status_recognition_end, data);
01303 if (recog->jconf->decodeopt.segment) {
01304 callback_add(recog, CALLBACK_EVENT_SEGMENT_BEGIN, status_segment_begin, data);
01305 callback_add(recog, CALLBACK_EVENT_SEGMENT_END, status_segment_end, data);
01306 }
01307 callback_add(recog, CALLBACK_EVENT_PASS1_BEGIN, status_pass1_begin, data);
01308 {
01309 JCONF_SEARCH *s;
01310 boolean ok_p;
01311 ok_p = TRUE;
01312 for(s=recog->jconf->search_root;s;s=s->next) {
01313 if (s->output.progout_flag) ok_p = FALSE;
01314 }
01315 if (ok_p) {
01316 have_progout = FALSE;
01317 } else {
01318 have_progout = TRUE;
01319 }
01320 }
01321 if (!recog->jconf->decodeopt.realtime_flag && verbose_flag && ! have_progout) {
01322 callback_add(recog, CALLBACK_EVENT_PASS1_FRAME, frame_indicator, data);
01323 }
01324 callback_add(recog, CALLBACK_RESULT_PASS1_INTERIM, result_pass1_current, data);
01325 callback_add(recog, CALLBACK_RESULT_PASS1, result_pass1, data);
01326 #ifdef WORD_GRAPH
01327 callback_add(recog, CALLBACK_RESULT_PASS1_GRAPH, result_pass1_graph, data);
01328 #endif
01329 callback_add(recog, CALLBACK_EVENT_PASS1_END, status_pass1_end, data);
01330 callback_add(recog, CALLBACK_STATUS_PARAM, status_param, data);
01331 callback_add(recog, CALLBACK_EVENT_PASS2_BEGIN, status_pass2_begin, data);
01332 callback_add(recog, CALLBACK_EVENT_PASS2_END, status_pass2_end, data);
01333 callback_add(recog, CALLBACK_RESULT, result_pass2, data);
01334 callback_add(recog, CALLBACK_RESULT_GMM, result_gmm, data);
01335
01336 callback_add(recog, CALLBACK_RESULT_GRAPH, result_graph, data);
01337
01338 callback_add(recog, CALLBACK_RESULT_CONFNET, result_confnet, data);
01339
01340
01341
01342 callback_add(recog, CALLBACK_RESULT_PASS1_DETERMINED, result_pass1_determined, data);
01343
01344 }