?? recogmain.c
字號:
/** * @file recogmain.c * * <JA> * @brief 千急メイン簇眶 * </JA> * * <EN> * @brief Main function of recognition process. * </EN> * * @author Akinobu Lee * @date Wed Aug 8 14:53:53 2007 * * $Revision: 1.11 $ * *//* * Copyright (c) 1991-2007 Kawahara Lab., Kyoto University * Copyright (c) 1997-2000 Information-technology Promotion Agency, Japan * Copyright (c) 2000-2005 Shikano Lab., Nara Institute of Science and Technology * Copyright (c) 2005-2007 Julius project team, Nagoya Institute of Technology * All rights reserved *//** * @mainpage * * <EN> * This is a source code browser of Julius. * * - Sample code to use JuliusLib: julius-simple.c * - JuliusLib API reference: @ref jfunc * - List of callbacks: libjulius/include/julius/callback.h * * You can access documentation for files, functions and structures * from the tabs at the top of this page. * * </EN> * <JA> * これは Julius のソ〖スコ〖ドのブラウザですˉ * * - JuliusLibを蝗脫するサンプルコ〖ド: julius-simple/julius-simple.c * - JuliusLib API リファレンス¨ @ref jfunc * - コ〖ルバック 辦枉: libjulius/include/julius/callback.h * * ペ〖ジ懼嬸のタブからファイルˇ簇眶ˇ菇隴攣霹の棱湯を斧ることが叫丸ますˉ * * </JA> * *//** * @defgroup jfunc JuliusLib API * * <EN> * Here is a reference of all Julius library API functions. * </EN> * <JA> * Julius ライブラリ API 簇眶のリファレンスです. * </JA> * *//** * @defgroup engine Basic API * @ingroup jfunc * * <EN> * Basic functions to start-up and initialize engines. * </EN> * <JA> * 千急エンジンの肋年霹 * </JA> * *//** * @defgroup callback Callback API * @ingroup jfunc * * <EN> * Functions to add callback to get results and status. * </EN> * <JA> * 千急馮蔡やエンジン覺輪を夢るためのコ〖ルバック * </JA> * *//** * @defgroup pauseresume Pause and Resume API * @ingroup jfunc * * <EN> * Functions to pause / resume engine inputs. * </EN> * <JA> * エンジンの辦箕匿賄ˇ浩倡 * </JA> * *//** * @defgroup userfunc User function API * @ingroup jfunc * * <EN> * Functions to register user function to be applied inside Julius. * </EN> * <JA> * ユ〖ザ簇眶の判峽 * </JA> * *//** * @defgroup jfunc_process Process API * @ingroup jfunc * * <EN> * Functions to create / remove / (de)activate recognition process and models * on live. * </EN> * <JA> * モデルおよび千急プロセスの瓢弄納裁ˇ猴近ˇ銅跟步ˇ痰跟步 * </JA> * *//** * @defgroup grammar Grammar / Dictionary API * @ingroup jfunc * * <EN> * Functions to manage grammars or word dictionaries at run time. * </EN> * <JA> * 矢恕ˇ帽胳輯今の拎侯 * </JA> * *//** * @defgroup jconf Jconf configuration API * @ingroup jfunc * * <EN> * Functions to load / create configuration parameters. * </EN> * <JA> * Jconf 菇隴攣によるパラメ〖タ攫鼠の瓷妄 * </JA> * *//** * @defgroup instance LM/AM/SR instance API * @ingroup jfunc * * <EN> * Functions to handle modules and processes directly. * </EN> * <JA> * モデルモジュ〖ルやプロセスを木儡胺う簇眶ˉ * </JA> * */#define GLOBAL_VARIABLE_DEFINE ///< Actually make global vars in global.h#include <julius/julius.h>#include <signal.h>#if defined(_WIN32) && !defined(__CYGWIN32__)#include <mbctype.h>#include <mbstring.h>#endif/* ---------- utility functions -----------------------------------------*/#ifdef REPORT_MEMORY_USAGE/** * <JA> * 奶撅姜位箕に蝗脫メモリ翁を拇べて叫蝸する (Linux, sol2) * * </JA> * <EN> * Get process size and output on normal exit. (Linux, sol2) * * </EN> */static voidprint_mem(){ char buf[200]; sprintf(buf,"ps -o vsz,rss -p %d",getpid()); system(buf); fflush(stdout); fflush(stderr);}#endif /** * <EN> * allocate storage of recognition alignment results. * * @return the new pointer * </EN> * <JA> * アラインメント馮蔡の呈羌眷疥を澄瘦 * * @return 澄瘦された撾拌へのポインタ * </JA> * * @callgraph * @callergraph * */SentenceAlign *result_align_new(){ SentenceAlign *new; new = (SentenceAlign *)mymalloc(sizeof(SentenceAlign)); new->w = NULL; new->ph = NULL; new->loc = NULL; new->begin_frame = NULL; new->end_frame = NULL; new->avgscore = NULL; new->is_iwsp = NULL; new->next = NULL; return new;}/** * <EN> * free storage of recognition alignment results. * * @param a [i/o] alignment data to be released * </EN> * <JA> * アラインメント馮蔡の呈羌眷疥を澄瘦 * * @param a [i/o] 豺庶されるアラインメントデ〖タ * </JA> * * @callgraph * @callergraph * */voidresult_align_free(SentenceAlign *a){ if (a->w) free(a->w); if (a->ph) free(a->ph); if (a->loc) free(a->loc); if (a->begin_frame) free(a->begin_frame); if (a->end_frame) free(a->end_frame); if (a->avgscore) free(a->avgscore); if (a->is_iwsp) free(a->is_iwsp); free(a);}/** * <EN> * Allocate storage of recognition results. * </EN> * <JA> * 千急馮蔡の呈羌眷疥を澄瘦する. * </JA> * * @param r [out] recognition process instance * @param num [in] number of sentences to be output * * @callgraph * @callergraph * */voidresult_sentence_malloc(RecogProcess *r, int num){ int i; r->result.sent = (Sentence *)mymalloc(sizeof(Sentence) * num); for(i=0;i<num;i++) r->result.sent[i].align = NULL; r->result.sentnum = 0;}/** * <EN> * Free storage of recognition results. * </EN> * <JA> * 千急馮蔡の呈羌眷疥を豺庶する. * </JA> * * @param r [i/o] recognition process instance * * @callgraph * @callergraph */voidresult_sentence_free(RecogProcess *r){ int i; SentenceAlign *a, *atmp; if (r->result.sent) { for(i=0;i<r->result.sentnum;i++) { a = r->result.sent[i].align; while(a) { atmp = a->next; result_align_free(a); a = atmp; } } free(r->result.sent); r->result.sent = NULL; }}/** * <EN> * Clear all result storages for next input. * </EN> * <JA> * 千急馮蔡の呈羌眷疥を鏈てクリアする. * </JA> * * @param r [in] recognition process instance. * * @callgraph * @callergraph */voidclear_result(RecogProcess *r){#ifdef WORD_GRAPH /* clear 1st pass word graph output */ wordgraph_clean(&(r->result.wg1));#endif if (r->lmvar == LM_DFA_WORD) { if (r->result.status == J_RESULT_STATUS_SUCCESS) { /* clear word recog result of first pass as in final result */ free(r->result.sent); } } else { if (r->graphout) { if (r->config->graph.confnet) { /* free confusion network clusters */ cn_free_all(&(r->result.confnet)); } else if (r->config->graph.lattice) { } /* clear all wordgraph */ wordgraph_clean(&(r->result.wg)); } result_sentence_free(r); }}/* --------------------- speech buffering ------------------ *//** * <JA> * @brief 浮叫された不をバッファに瘦賂する adin_go() コ〖ルバック * * この簇眶は·浮叫された不蘭掐蝸を界肌 recog->speech に淡峽して * いく. バッファ借妄モ〖ド∈♂潤リアルタイムモ〖ド∷で千急を乖なう * ときに脫いられる. * * @param now [in] 浮叫された不蘭僑妨デ〖タの們室 * @param len [in] @a now の墓さ(サンプル眶) * @param recog [i/o] エンジンインスタンス * * @return エラ〖箕 -1 (adin_go は簍箕面們する)·奶撅箕 0 (adin_go は * 魯乖する)·惰粗姜位妥滇箕 1 (adin_go は附哼の不蘭惰粗を誓じる). * * </JA> * <EN> * @brief adin_go() callback to score triggered inputs to buffer. * * This function records the incomping speech segments detected in adin_go() * to recog->speech. This function will be used when recognition runs * in buffered mode (= non-realtime mode). * * @param now [in] input speech samples. * @param len [in] length of @a now in samples * @param recog [i/o] engine instance * * @return -1 on error (tell adin_go() to terminate), 0 on success (tell * adin_go() to continue recording), or 1 when this function requires * input segmentation. * </EN> */intadin_cut_callback_store_buffer(SP16 *now, int len, Recog *recog){ if (recog->speechlen == 0) { /* first part of a segment */ if (!recog->process_active) { return(1); } } if (recog->speechlen + len > recog->speechalloclen) { while (recog->speechlen + len > recog->speechalloclen) { recog->speechalloclen += MAX_SPEECH_ALLOC_STEP; } if (recog->speech == NULL) { recog->speech = (SP16 *)mymalloc(sizeof(SP16) * recog->speechalloclen); } else { if (debug2_flag) { jlog("STAT: expanding recog->speech to %d samples\n", recog->speechalloclen); } recog->speech = (SP16 *)myrealloc(recog->speech, sizeof(SP16) * recog->speechalloclen); } } /* store now[0..len] to recog->speech[recog->speechlen] */ memcpy(&(recog->speech[recog->speechlen]), now, len * sizeof(SP16)); recog->speechlen += len; return(0); /* tell adin_go to continue reading */}/* --------------------- adin check callback --------------- *//** * <JA> * @brief 不蘭掐蝸面に年袋弄に悸乖されるコ〖ルバック. * * この簇眶は·adin_go() にて不蘭掐蝸略ち·あるいは不蘭千急面に * 年袋弄に帆り手し鈣び叫される簇眶である. ユ〖ザ年盜のコ〖ルバック * (CALLBACK_POLL) の鈣び叫し·および面們冉年を乖う. * * @param recog [in] エンジンインスタンス * * @return 奶撅箕 0, 簍箕面們を妥滇箕 -2, 千急面賄の妥滇箕は -1 を手す. * </JA> * <EN> * @brief callback function periodically called while input. * * This function will be called periodically from adin_go() while * waiting input or processing recognition. It will call user-defined * callback registered in CALLBACK_POLL, check for the process * status and issue recognition termination request. * * @param recog [in] engine instance * * @return 0 normally, -2 for immediate termination, and -1 if requesting * recognition stop. * * </EN> */static intcallback_check_in_adin(Recog *recog){ /* module: check command and terminate recording when requested */ callback_exec(CALLBACK_POLL, recog); /* With audio input via adinnet, TERMINATE command will issue terminate command to the adinnet client. The client then stops recording immediately and return end-of-segment ack. Then it will cause this process to stop recognition as normal. So we need not to perform immediate termination at this callback, but just ignore the results in the main.c. */#if 1 if (recog->process_want_terminate) { /* TERMINATE ... force termination */ return(-2); } if (recog->process_want_reload) { return(-1); }#else if (recog->process_want_terminate /* TERMINATE ... force termination */ && recog->jconf->input.speech_input != SP_ADINNET) { return(-2); } if (recog->process_want_reload) { return(-1); }#endif return(0);}/*********************//* open input stream *//*********************//** * <EN> * Open input stream. * </EN> * <JA> * 不蘭掐蝸ストリ〖ムを倡く * </JA> * * @param recog [i/o] engine instance * @param file_or_dev_name [in] file or device name of the device * * @return 0 on success, -1 on error, -2 on device initialization error. * * @callgraph
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -