Beispiel #1
0
/**
 * @brief  Top function to adjust parameter.
 *
 * It compares the types for the given parameter @a param and
 * %HMM definition @a hmminfo.  If type is not the same, adjustment will be
 * tried.
 *
 * @param hmminfo [in] HTK %HMM definition
 * @param param [i/o] input parameter, will be freed if adjustment was
 * performed in this function
 * @param vflag [in] if TRUE, output verbose messages
 *
 * @return 1 on success, 0 if no adjustment needed, or -1 on failure (in case
 * parameter type does not match even by the adjustment).
 */
int
param_check_and_adjust(HTK_HMM_INFO *hmminfo, HTK_Param *param, boolean vflag)
{
    char pbuf[80],hbuf[80];

    param_code2str(pbuf, (short)(param->header.samptype & ~(F_COMPRESS | F_CHECKSUM)), FALSE);
    param_code2str(hbuf, hmminfo->opt.param_type, FALSE);
    if (!check_param_basetype(hmminfo, param)) {
        /* error if base type not match */
        jlog("Error: paramselect: incompatible parameter type\n");
        jlog("Error: paramselect:  HMM   trained   by  %s(%d)\n", hbuf, hmminfo->opt.vec_size);
        jlog("Error: paramselect:  input parameter is  %s(%d)\n", pbuf, param->veclen);
        return -1;
    }
    if (!check_param_coherence(hmminfo, param)) {
        /* try to select needed parameter vector */
        if (vflag) jlog("Stat: paramselect: attaching %s\n", pbuf);
        if (select_param_kind(param, hmminfo->opt.param_type) == FALSE) {
            if (vflag) jlog("Error: paramselect: failed to attach to %s\n", hbuf);

            jlog("Error: paramselect: incompatible parameter type\n");
            jlog("Error: paramselect:  HMM   trained   by  %s(%d)\n", hbuf, hmminfo->opt.vec_size);
            jlog("Error: paramselect:  input parameter is  %s(%d)\n", pbuf, param->veclen);
            return -1;
        }
        param_code2str(pbuf, param->header.samptype, FALSE);
        if (vflag) jlog("Stat: paramselect: attached to %s\n", pbuf);
        return(1);
    }
    return(0);
}
/** 
 * <JA>
 * @brief  第1パス平行認識処理の準備
 *
 * 計算用変数をリセットし,各種データを準備する. 
 * この関数は,ある入力(あるいはセグメント)の認識が
 * 始まる前に呼ばれる. 
 * 
 * </JA>
 * <EN>
 * @brief  Preparation for the on-the-fly 1st pass decoding.
 *
 * Variables are reset and data are prepared for the next input recognition.
 *
 * This function will be called before starting each input (segment).
 * 
 * </EN>
 *
 * @param recog [i/o] engine instance
 *
 * @return TRUE on success. FALSE on failure.
 *
 * @callgraph
 * @callergraph
 * 
 */
boolean
RealTimePipeLinePrepare(Recog *recog)
{
  RealBeam *r;
  PROCESS_AM *am;
  MFCCCalc *mfcc;
#ifdef SPSEGMENT_NAIST
  RecogProcess *p;
#endif

  r = &(recog->real);

  /* 計算用の変数を初期化 */
  /* initialize variables for computation */
  r->windownum = 0;
  /* parameter check */
  for(mfcc = recog->mfcclist; mfcc; mfcc = mfcc->next) {
    /* パラメータ初期化 */
    /* parameter initialization */
    if (recog->jconf->input.speech_input == SP_MFCMODULE) {
      if (mfc_module_set_header(mfcc, recog) == FALSE) return FALSE;
    } else {
      init_param(mfcc);
    }
    /* フレームごとのパラメータベクトル保存の領域を確保 */
    /* あとで必要に応じて伸長される */
    if (param_alloc(mfcc->param, 1, mfcc->param->veclen) == FALSE) {
      j_internal_error("ERROR: segmented: failed to allocate memory for rest param\n");
    }
    /* フレーム数をリセット */
    /* reset frame count */
    mfcc->f = 0;
  }
  /* 準備した param 構造体のデータのパラメータ型を音響モデルとチェックする */
  /* check type coherence between param and hmminfo here */
  if (recog->jconf->input.paramtype_check_flag) {
    for(am=recog->amlist;am;am=am->next) {
      if (!check_param_coherence(am->hmminfo, am->mfcc->param)) {
	jlog("ERROR: input parameter type does not match AM\n");
	return FALSE;
      }
    }
  }

  /* 計算用のワークエリアを準備 */
  /* prepare work area for calculation */
  if (recog->jconf->input.type == INPUT_WAVEFORM) {
    reset_mfcc(recog);
  }
  /* 音響尤度計算用キャッシュを準備 */
  /* prepare cache area for acoustic computation of HMM states and mixtures */
  for(am=recog->amlist;am;am=am->next) {
    outprob_prepare(&(am->hmmwrk), r->maxframelen);
  }

#ifdef BACKEND_VAD
  if (recog->jconf->decodeopt.segment) {
    /* initialize segmentation parameters */
    spsegment_init(recog);
  }
#else
  recog->triggered = FALSE;
#endif

#ifdef DEBUG_VTLN_ALPHA_TEST
  /* store speech */
  recog->speechlen = 0;
#endif

  return TRUE;
}