/** * <JA> * 設定パラメータに従い音声入力デバイスをセットアップする. * * @param recog [i/o] エンジンインスタンス * * </JA> * <EN> * Set up audio input device according to the jconf configurations. * * @param recog [i/o] engine instance * </EN> * * @callgraph * @callergraph */ boolean adin_initialize(Recog *recog) { char *arg = NULL; ADIn *adin; Jconf *jconf; #ifdef ENABLE_PLUGIN FUNC_INT func; int sid; #endif adin = recog->adin; jconf = recog->jconf; jlog("STAT: ###### initialize input device\n"); /* select input device: file, mic, netaudio, etc... */ #ifdef ENABLE_PLUGIN sid = jconf->input.plugin_source; if (sid >= 0) { /* set plugin properties and functions to adin */ func = (FUNC_INT) plugin_get_func(sid, "adin_get_configuration"); if (func == NULL) { jlog("ERROR: invalid plugin: adin_get_configuration() not exist\n"); return FALSE; } adin->silence_cut_default = (*func)(1); adin->enable_thread = (*func)(2); adin->ad_standby = (boolean (*)(int, void *)) plugin_get_func(sid, "adin_standby"); adin->ad_begin = (boolean (*)(char *)) plugin_get_func(sid, "adin_open"); adin->ad_end = (boolean (*)()) plugin_get_func(sid, "adin_close"); adin->ad_resume = (boolean (*)()) plugin_get_func(sid, "adin_resume"); adin->ad_pause = (boolean (*)()) plugin_get_func(sid, "adin_pause"); adin->ad_terminate = (boolean (*)()) plugin_get_func(sid, "adin_terminate"); adin->ad_read = (int (*)(SP16 *, int)) plugin_get_func(sid, "adin_read"); adin->ad_input_name = (char * (*)()) plugin_get_func(sid, "adin_input_name"); if (adin->ad_read == NULL) { jlog("ERROR: m_adin: selected plugin has no function adin_read()\n"); return FALSE; } } else { #endif /* built-in */ if (adin_select(adin, jconf->input.speech_input, jconf->input.device) == FALSE) { jlog("ERROR: m_adin: failed to select input device\n"); return FALSE; } /* set sampling frequency and device-dependent configuration (argument is device-dependent) */ switch(jconf->input.speech_input) { case SP_ADINNET: /* arg: port number */ arg = mymalloc(100); sprintf(arg, "%d", jconf->input.adinnet_port); break; case SP_RAWFILE: /* arg: filename of file list (if any) */ if (jconf->input.inputlist_filename != NULL) { arg = mymalloc(strlen(jconf->input.inputlist_filename)+1); strcpy(arg, jconf->input.inputlist_filename); } else { arg = NULL; } break; case SP_STDIN: arg = NULL; break; #ifdef USE_NETAUDIO case SP_NETAUDIO: /* netaudio server/port name */ arg = mymalloc(strlen(jconf->input.netaudio_devname)+1); strcpy(arg, jconf->input.netaudio_devname); break; #endif } #ifdef ENABLE_PLUGIN } #endif if (adin_setup_all(adin, jconf, arg) == FALSE) { return FALSE; } if (arg != NULL) free(arg); return TRUE; }
/** * <JA> * メイン関数 * * @param argc [in] 引数列の長さ * @param argv [in] 引数列 * * @return * </JA>エラー時 1,通常終了時 0 を返す. * <EN> * Main function. * * @param argc [in] number of argument. * @param argv [in] array of arguments. * * @return 1 on error, 0 on success. * </EN> */ int main(int argc, char *argv[]) { int silence_cut = 1; /* 0=disabled, 1=enabled, 2=undef */ /* parse option */ opt_parse(argc, argv); /* select microphone input */ if (adin_select(SP_MIC) == FALSE) { j_printerr("Error: microphone input is not supported\n"); return(1); } /* ready the microphone (arg is dummy) */ if (use_48to16) { if (sfreq != 16000) { j_printerr("Error: in 48kHz mode, required rate should be 16kHz!\n"); return(1); } /* setup for down sampling */ adin_setup_48to16(); /* set device sampling rate to 48kHz */ if (adin_standby(48000, NULL) == FALSE) { /* fail */ j_printerr("Error: failed to ready input device to 48kHz\n"); return(1); } } else { if (adin_standby(sfreq, NULL) == FALSE) { j_printerr("Error: failed to standby input\n"); return(1); } } /* set device-independent param */ adin_setup_param(silence_cut, strip_zero_sample, level_thres, zero_cross_num, margin, margin, sfreq, TRUE, use_zmean);/* use same margin for head and tail */ /* file check */ if (!stout) { if (access(filename, F_OK) == 0) { if (access(filename, W_OK) == 0) { fprintf(stderr, "Warning: overwriting file \"%s\"\n", filename); } else { perror("adinrec"); return(1); } } } /* output file will be opened when triggered (not here) */ /* set interrupt signal handler to properly close output file */ if (signal(SIGINT, interrupt_record) == SIG_ERR) { fprintf(stderr, "Warning: signal intterupt may collapse output\n"); } /* do recoding */ speechlen = 0; adin_begin(); j_printerr("<<< please speak >>>"); /* moved from adin-cut.c */ adin_go(adin_callback_file, NULL); adin_end(); /* close file and output status */ close_file(); return 1; }