Esempio n. 1
0
/**
 * Callback to output final recognition result.
 * This function will be called just after recognition of an input ends
 *
 */
static void recdone(Recog *recog, void *speech_sys)
{
	int i, j;
	int len;
	WORD_INFO *winfo;
	WORD_ID *seq;
	int seqnum;
	int n;
	Sentence *s;
	RecogProcess *r;
	HMM_Logical *p;
	SentenceAlign *align;

	/*	all recognition results are stored at each recognition process
	 instance
	 */
	for(r=recog->process_list;r;r=r->next)
	{

		/* skip the process if the process is not alive */
		if (! r->live) continue;

		/* result are in r->result.	See recog.h for details */

		/* check result status */
		if (r->result.status < 0)
		{
			/* no results obtained */
			debug_julius_result(r);
			/* continue to next process instance */
			continue;
		}

		/* output results for all the obtained sentences */
		winfo = r->lm->winfo;

		int it_end = min(r->result.sentnum, 1);
		for(n = 0; n < it_end; n++) { // for all sentences
			s = &(r->result.sent[n]);
			seq = s->word;
			seqnum = s->word_num;

			// output word sequence like Julius
			printf("sentence%d:", n+1);
			for(i=0;i<seqnum;i++) printf(" %s", winfo->woutput[seq[i]]);
			printf("\ncmscore%d:", n+1);
			for(i=0;i<seqnum;i++) printf(" %5.3f", s->confidence[i]);
			// AM and LM scores
			printf("\nscore%d: %f", n+1, s->score);
			put_hypo_phoneme(seq, seqnum, winfo);

			((SpeechSystem*)speech_sys)->detected.sentences = "";
			for(i=1;i<seqnum-1;i++)
				((SpeechSystem*)speech_sys)->detected.sentences += winfo->woutput[seq[i]];
		}
	}

	/* flush output buffer */
	fflush(stdout);
}
Esempio n. 2
0
void output_result(Recog *recog, void *app_)
{
  Application *app = (Application *)app_;
  int i, j;
  int len;
  WORD_INFO *winfo;
  WORD_ID *seq;
  int seqnum;
  int n;
  Sentence *s;
  RecogProcess *r;
  HMM_Logical *p;
  SentenceAlign *align;
  boolean multi;

  if (recog->process_list->next != NULL) 
    multi = TRUE;
  else 
    multi = FALSE;

  /* all recognition results are stored at each recognition process
     instance */
  for(r=recog->process_list;r;r=r->next) {

    /* skip the process if the process is not alive */
    if (! r->live) continue;

    /* result are in r->result.  See recog.h for details */
    
    /* check result status */
    if (r->result.status < 0) {      /* no results obtained */
#if 0
      /* outout message according to the status code */
      switch(r->result.status) {
      case J_RESULT_STATUS_REJECT_POWER:
	fprintf(stderr, "<input rejected by power>\n");
	break;
      case J_RESULT_STATUS_TERMINATE:
	fprintf(stderr, "<input teminated by request>\n");
	break;
      case J_RESULT_STATUS_ONLY_SILENCE:
	fprintf(stderr, "<input rejected by decoder (silence input result)>\n");
	break;
      case J_RESULT_STATUS_REJECT_GMM:
	fprintf(stderr, "<input rejected by GMM>\n");
	break;
      case J_RESULT_STATUS_REJECT_SHORT:
	fprintf(stderr, "<input rejected by short input>\n");
	break;
      case J_RESULT_STATUS_FAIL:
	fprintf(stderr, "<search failed>\n");
	break;
      }
      /* continue to next process instance */
#endif
      continue;
    }
#if 0
    fprintf(stderr, "\n");
    fprintf(stderr, "search id:%d name:%s\n", r->config->id, r->config->name);
#endif
    /* output results for all the obtained sentences */
    winfo = r->lm->winfo;

    for(n = 0; n < r->result.sentnum; n++) { /* for all sentences */

      s = &(r->result.sent[n]);
      seq = s->word;
      seqnum = s->word_num;

#if 0
      /* output word sequence like Julius */
      fprintf(stderr, "sentence%d:", n+1);
      for(i=0;i<seqnum;i++) 
	fprintf(stderr, " %s", to_utf(winfo->woutput[seq[i]]));
      fprintf(stderr, "\n");
#endif
      if (n == 0 and seqnum == 3) {
	app->onSpeechRecognized(to_utf(winfo->woutput[seq[1]]));
      }
#if 0
      /* LM entry sequence */
      fprintf(stderr, "wseq%d:", n+1);
      for(i=0;i<seqnum;i++) 
	fprintf(stderr, " %s", to_utf(winfo->wname[seq[i]]));
      fprintf(stderr, "\n");
      /* phoneme sequence */
      fprintf(stderr, "phseq%d:", n+1);
      put_hypo_phoneme(seq, seqnum, winfo);
      //fprintf(stderr, "\n");
      /* confidence scores */
      fprintf(stderr, "cmscore%d:", n+1);
      for (i=0;i<seqnum; i++) 
	fprintf(stderr, " %5.3f", s->confidence[i]);
      fprintf(stderr, "\n");
      /* AM and LM scores */
      fprintf(stderr, "score%d: %f", n+1, s->score);
      if (r->lmtype == LM_PROB) { /* if this process uses N-gram */
	fprintf(stderr, " (AM: %f  LM: %f)", s->score_am, s->score_lm);
      }
      fprintf(stderr, "\n");
      if (r->lmtype == LM_DFA) { /* if this process uses DFA grammar */
	/* output which grammar the hypothesis belongs to
	   when using multiple grammars */
	if (multigram_get_all_num(r->lm) > 1) {
	  fprintf(stderr, "grammar%d: %d\n", n+1, s->gram_id);
	}
      }
#endif
    }
  }
#if 0
  fflush(stderr);
#endif
}