⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 realtime-1stpass.c

📁 julius version 4.12.about sound recognition.
💻 C
📖 第 1 页 / 共 4 页
字号:
 * @callergraph *  */intRealTimePipeLine(SP16 *Speech, int nowlen, Recog *recog) /* Speech[0...nowlen] = input */{  int i, now, ret;  MFCCCalc *mfcc;  RealBeam *r;  r = &(recog->real);#ifdef DEBUG_VTLN_ALPHA_TEST  /* store speech */  adin_cut_callback_store_buffer(Speech, nowlen, recog);#endif  /* window[0..windownum-1] は涟搀の钙び叫しで荒った不兰デ〖タが呈羌されている */  /* window[0..windownum-1] are speech data left from previous call */  /* 借妄脱ポインタを介袋步 */  /* initialize pointer for local processing */  now = 0;    /* 千急借妄がセグメント妥滇で姜わったのかどうかのフラグをリセット */  /* reset flag which indicates whether the input has ended with segmentation request */  r->last_is_segmented = FALSE;#ifdef RDEBUG  printf("got %d samples\n", nowlen);#endif  while (now < nowlen) {	/* till whole input is processed */    /* 掐蜗墓が maxframelen に茫したらここで动扩姜位 */    /* if input length reaches maximum buffer size, terminate 1st pass here */    for (mfcc = recog->mfcclist; mfcc; mfcc = mfcc->next) {      if (mfcc->f >= r->maxframelen) return(1);    }    /* 岭バッファを虽められるだけ虽める */    /* fill window buffer as many as possible */    for(i = min(r->windowlen - r->windownum, nowlen - now); i > 0 ; i--)      r->window[r->windownum++] = (float) Speech[now++];    /* もし岭バッファが虽まらなければ, このセグメントの借妄はここで姜わる.        借妄されなかったサンプル (window[0..windownum-1]) は肌搀に积ち臂し. */    /* if window buffer was not filled, end processing here, keeping the       rest samples (window[0..windownum-1]) in the window buffer. */    if (r->windownum < r->windowlen) break;#ifdef RDEBUG    /*    printf("%d used, %d rest\n", now, nowlen - now);	  printf("[f = %d]\n", f);*/#endif    for (mfcc = recog->mfcclist; mfcc; mfcc = mfcc->next) {      mfcc->valid = FALSE;      /* 岭柒の不兰侨妨から泼魔翁を纷换して r->tmpmfcc に呈羌  */      /* calculate a parameter vector from current waveform windows	 and store to r->tmpmfcc */      if ((*(recog->calc_vector))(mfcc, r->window, r->windowlen)) {#ifdef ENABLE_PLUGIN	/* call post-process plugin if exist */	plugin_exec_vector_postprocess(mfcc->tmpmfcc, mfcc->param->veclen, mfcc->f);#endif	/* MFCC窗喇·判峡 */  	mfcc->valid = TRUE;	/* now get the MFCC vector of current frame, now store it to param */	if (param_alloc(mfcc->param, mfcc->f + 1, mfcc->param->veclen) == FALSE) {	  jlog("ERROR: failed to allocate memory for incoming MFCC vectors\n");	  return -1;	}	memcpy(mfcc->param->parvec[mfcc->f], mfcc->tmpmfcc, sizeof(VECT) * mfcc->param->veclen);#ifdef RDEBUG	printf("DeltaBuf: %02d: got frame %d\n", mfcc->id, mfcc->f);#endif      }    }    /* 借妄を1フレ〖ム渴める */    /* proceed one frame */    ret = proceed_one_frame(recog);    if (ret == 1 && recog->jconf->decodeopt.segment) {      /* ショ〖トポ〖ズセグメンテ〖ション: バッファに荒っているデ〖タを	 侍に瘦积して·肌搀の呵介に借妄する */      /* short pause segmentation: there is some data left in buffer, so	 we should keep them for next processing */      r->rest_len = nowlen - now;      if (r->rest_len > 0) {	/* copy rest samples to rest_Speech */	if (r->rest_Speech == NULL) {	  r->rest_alloc_len = r->rest_len;	  r->rest_Speech = (SP16 *)mymalloc(sizeof(SP16)*r->rest_alloc_len);	} else if (r->rest_alloc_len < r->rest_len) {	  r->rest_alloc_len = r->rest_len;	  r->rest_Speech = (SP16 *)myrealloc(r->rest_Speech, sizeof(SP16)*r->rest_alloc_len);	}	memcpy(r->rest_Speech, &(Speech[now]), sizeof(SP16) * r->rest_len);      }    }    if (ret != 0) return ret;    /* 1フレ〖ム借妄が渴んだのでポインタを渴める */    /* proceed frame pointer */    for (mfcc = recog->mfcclist; mfcc; mfcc = mfcc->next) {      if (!mfcc->valid) continue;      mfcc->f++;    }    /* 岭バッファを借妄が姜わった尸シフト */    /* shift window */    memmove(r->window, &(r->window[recog->jconf->input.frameshift]), sizeof(SP16) * (r->windowlen - recog->jconf->input.frameshift));    r->windownum -= recog->jconf->input.frameshift;  }  /* 涂えられた不兰セグメントに滦する千急借妄が链て姜位     钙び叫し傅に, 掐蜗を鲁けるよう帕える */  /* input segment is fully processed     tell the caller to continue input */  return(0);			}/**  * <JA> * @brief  セグメントの千急浩倡借妄 * * この簇眶はデコ〖ダベ〖スVADやショ〖トポ〖ズセグメンテ〖ションによって * 掐蜗がセグメントに磊られた眷圭に·その稿の千急の浩倡に簇する借妄を乖う.  * 恶挛弄には·掐蜗の千急を倡幌する涟に·涟搀の掐蜗セグメントにおける * 船提し尸のMFCC误から千急を倡幌する. さらに·涟搀のセグメンテ〖ション箕に * 踏借妄だった荒りの不兰サンプルがあればそれも借妄する. * * @param recog [i/o] エンジンインスタンス *  * @return エラ〖箕 -1·赖撅箕 0 を手す. また·この掐蜗们室の借妄面に * 矢鞠の惰磊りが斧つかったときは妈1パスをここで面们するために 1 を手す.  * </JA> * </JA> * <EN> * @brief  Resuming recognition for short pause segmentation. * * This function process overlapped data and remaining speech prior * to the next input when input was segmented at last processing. * * @param recog [i/o] engine instance * * @return -1 on error (tell caller to terminate), 0 on success (allow caller * to call me for the next segment), or 1 when an end-of-sentence detected * at this point (in that case caller will stop input and go to 2nd pass) * </EN> * * @callgraph * @callergraph *  */intRealTimeResume(Recog *recog){  MFCCCalc *mfcc;  RealBeam *r;  boolean ok_p;#ifdef SPSEGMENT_NAIST  RecogProcess *p;#endif  PROCESS_AM *am;  r = &(recog->real);  /* 纷换脱のワ〖クエリアを洁洒 */  /* 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);  }  /* param にある链パラメ〖タを借妄する洁洒 */  /* prepare to process all data in param */  for(mfcc = recog->mfcclist; mfcc; mfcc = mfcc->next) {    if (mfcc->param->samplenum == 0) mfcc->valid = FALSE;    else mfcc->valid = TRUE;#ifdef RDEBUG    printf("Resume: %02d: f=%d\n", mfcc->id, mfcc->mfcc->param->samplenum-1);#endif    /* フレ〖ム眶をリセット */    /* reset frame count */    mfcc->f = 0;    /* MAP-CMN の介袋步 */    /* Prepare for MAP-CMN */    if (mfcc->para->cmn || mfcc->para->cvn) CMN_realtime_prepare(mfcc->cmn.wrk);  }#ifdef BACKEND_VAD  if (recog->jconf->decodeopt.segment) {    spsegment_init(recog);  }  /* not exec pass1 begin callback here */#else  recog->triggered = FALSE;  for (mfcc = recog->mfcclist; mfcc; mfcc = mfcc->next) {    if (!mfcc->valid) continue;    callback_exec(CALLBACK_EVENT_SEGMENT_BEGIN, recog);    callback_exec(CALLBACK_EVENT_PASS1_BEGIN, recog);    recog->triggered = TRUE;    break;  }#endif  /* param 柒の链フレ〖ムについて千急借妄を渴める */  /* proceed recognition for all frames in param */  while(1) {    ok_p = TRUE;    for (mfcc = recog->mfcclist; mfcc; mfcc = mfcc->next) {      if (! mfcc->valid) continue;      if (mfcc->f < mfcc->param->samplenum) {	mfcc->valid = TRUE;	ok_p = FALSE;      } else {	mfcc->valid = FALSE;      }    }    if (ok_p) {      /* すべての MFCC が姜わりに茫したのでル〖プ姜位 */      /* all MFCC has been processed, end of loop  */      break;    }    /* 称インスタンスについて mfcc->f の千急借妄を1フレ〖ム渴める */    switch (decode_proceed(recog)) {    case -1: /* error */      return -1;      break;    case 0:			/* success */      break;    case 1:			/* segmented */      /* segmented, end procs ([0..f])*/      r->last_is_segmented = TRUE;      return 1;		/* segmented by this function */    }#ifdef BACKEND_VAD    /* check up trigger in case of VAD segmentation */    if (recog->jconf->decodeopt.segment) {      if (recog->triggered == FALSE) {	if (spsegment_trigger_sync(recog)) {	  callback_exec(CALLBACK_EVENT_SEGMENT_BEGIN, recog);	  callback_exec(CALLBACK_EVENT_PASS1_BEGIN, recog);	  recog->triggered = TRUE;	}      }    }#endif    /* call frame-wise callback */    callback_exec(CALLBACK_EVENT_PASS1_FRAME, recog);    /* 1フレ〖ム借妄が渴んだのでポインタを渴める */    /* proceed frame pointer */    for (mfcc = recog->mfcclist; mfcc; mfcc = mfcc->next) {      if (!mfcc->valid) continue;      mfcc->f++;    }  }  /* 涟搀のセグメント箕に掐蜗をシフトしていない尸をシフトする */  /* do the last shift here */  if (recog->jconf->input.type == INPUT_WAVEFORM) {    memmove(r->window, &(r->window[recog->jconf->input.frameshift]), sizeof(SP16) * (r->windowlen - recog->jconf->input.frameshift));    r->windownum -= recog->jconf->input.frameshift;    /* これで浩倡の洁洒が腊ったので,まずは涟搀の借妄で荒っていた不兰デ〖タから       借妄する */    /* now that the search status has been prepared for the next input, we       first process the rest unprocessed samples at the last session */    if (r->rest_len > 0) {      return(RealTimePipeLine(r->rest_Speech, r->rest_len, recog));    }  }  /* 糠惮の掐蜗に滦して千急借妄は鲁く∧ */  /* the recognition process will continue for the newly incoming samples... */  return 0;}/**  * <JA> * @brief  妈1パス士乖千急借妄の姜位借妄を乖う. * * この簇眶は妈1パス姜位箕に钙ばれ·掐蜗墓を澄年したあと· * decode_end() ∈セグメントで姜位したときは decode_end_segmented()∷を * 钙び叫して妈1パス姜位借妄を乖う.  * * もし不兰掐蜗ストリ〖ムの姜位によって千急が姜わった眷圭∈ファイル掐蜗で * 姜眉に茫した眷圭など∷は·デルタバッファに踏借妄の掐蜗が荒っているので· * それをここで借妄する.  * * @param recog [i/o] エンジンインスタンス *  * @return 借妄喇根箕 TRUE, エラ〖箕 FALSE を手す.  * </JA> * <EN> * @brief  Finalize the 1st pass on-the-fly decoding. * * This function will be called after the 1st pass processing ends. * It fix the input length of parameter vector sequence, call * decode_end() (or decode_end_segmented() when last input was ended * by segmentation) to finalize the 1st pass. * * If the last input was ended by end-of-stream (in case input reached * EOF in file input etc.), process the rest samples remaining in the * delta buffers. * * @param recog [i/o] engine instance *  * @return TRUE on success, or FALSE on error. * </EN> */booleanRealTimeParam(Recog *recog){  boolean ret1, ret2;  RealBeam *r;  int ret;  int maxf;  boolean ok_p;  MFCCCalc *mfcc;  Value *para;#ifdef RDEBUG  int i;#endif  r = &(recog->real);  if (r->last_is_segmented) {    /* RealTimePipeLine で千急借妄娄の妄统により千急が面们した眷圭,       附觉轮のMFCC纷换デ〖タをそのまま肌搀へ瘦积する涩妥があるので,       MFCC纷换姜位借妄を乖わずに妈1パスの冯蔡のみ叫蜗して姜わる. */    /* When input segmented by recognition process in RealTimePipeLine(),       we have to keep the whole current status of MFCC computation to the       next call.  So here we only output the 1st pass result. */    for (mfcc = recog->mfcclist; mfcc; mfcc = mfcc->next) {      mfcc->param->header.samplenum = mfcc->f + 1;/* len = lastid + 1 */      mfcc->param->samplenum = mfcc->f + 1;    }    decode_end_segmented(recog);    /* この惰粗の param デ〖タを妈2パスのために手す */    /* return obtained parameter for 2nd pass */    return(TRUE);  }  if (recog->jconf->input.type == INPUT_VECTOR) {    /* finalize real-time 1st pass */    for (mfcc = recog->mfcclist; mfcc; mfcc = mfcc->next) {      mfcc->param->header.samplenum = mfcc->f;      mfcc->param->samplenum = mfcc->f;    }    /* 呵姜フレ〖ム借妄を乖い·千急の冯蔡叫蜗と姜位借妄を乖う */    decode_end(recog);    return TRUE;  }  /* MFCC纷换の姜位借妄を乖う: 呵稿の觅变フレ〖ム尸を借妄 */  /* finish MFCC computation for the last delayed frames */  for (mfcc = recog->mfcclist; mfcc; mfcc = mfcc->next) {    if (mfcc->para->delta || mfcc->para->acc) {      mfcc->valid = TRUE;    } else {      mfcc->valid = FALSE;    }  }  /* loop until all data has been flushed */  while (1) {    /* if all mfcc became invalid, exit loop here */    ok_p = FALSE;    for (mfcc = recog->mfcclist; mfcc; mfcc = mfcc->next) {      if (mfcc->valid) {	ok_p = TRUE;	break;      }    }    if (!ok_p) break;    /* try to get 1 frame for all mfcc instances */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -