void SpeechSystem::setup() { // ewwww jconf = j_config_load_file_new(const_cast<char*>(jconf_filename.c_str())); /* 2. create recognition instance according to the jconf */ /* it loads models, setup final parameters, build lexicon and set up work area for recognition */ recog = j_create_instance_from_jconf(jconf); if (recog == NULL) { fprintf(stderr, "Error in startup\n"); return; } /*********************/ /* Register callback */ /*********************/ /* register result callback functions */ callback_add(recog, CALLBACK_EVENT_SPEECH_READY, recready, this); callback_add(recog, CALLBACK_EVENT_SPEECH_START, recstart, this); callback_add(recog, CALLBACK_RESULT, recdone, this); /**************************/ /* Initialize audio input */ /**************************/ /* initialize audio input device */ /* ad-in thread starts at this time for microphone */ if (j_adin_init(recog) == FALSE) { /* error */ return; } //#ifdef JULIUS_DEBUG /* output system information to log */ j_recog_info(recog); //#endif /***********************************/ /* Open input stream and recognize */ /***********************************/ /* raw speech input (microphone etc.) */ switch(j_open_stream(recog, NULL)) { case 0: /* succeeded */ break; case -1: /* error */ fprintf(stderr, "error in input stream\n"); return; case -2: /* end of recognition process */ fprintf(stderr, "failed to begin input stream\n"); return; } startThread(true, false); // blocking, verbose }
void cTumkwsjSink::setupCallbacks(Recog *recog, void *data) { // callback_add(recog, CALLBACK_EVENT_PROCESS_ONLINE, status_process_online, data); // callback_add(recog, CALLBACK_EVENT_PROCESS_OFFLINE, status_process_offline, data); // callback_add(recog, CALLBACK_EVENT_SPEECH_READY, status_recready, data); // callback_add(recog, CALLBACK_EVENT_SPEECH_START, status_recstart, data); // callback_add(recog, CALLBACK_EVENT_SPEECH_STOP, status_recend, data); // callback_add(recog, CALLBACK_EVENT_RECOGNITION_BEGIN, status_recognition_begin, data); // callback_add(recog, CALLBACK_EVENT_RECOGNITION_END, status_recognition_end, data); // if (recog->jconf->decodeopt.segment) { /* short pause segmentation */ // callback_add(recog, CALLBACK_EVENT_SEGMENT_BEGIN, status_segment_begin, data); // callback_add(recog, CALLBACK_EVENT_SEGMENT_END, status_segment_end, data); // } callback_add(recog, CALLBACK_EVENT_PASS1_BEGIN, status_pass1_begin_loader, data); //sets wst=0 // { // JCONF_SEARCH *s; // boolean ok_p; // ok_p = TRUE; // for(s=recog->jconf->search_root;s;s=s->next) { // if (s->output.progout_flag) ok_p = FALSE; // } // if (ok_p) { // have_progout = FALSE; // } else { // have_progout = TRUE; // } // } // if (!recog->jconf->decodeopt.realtime_flag && verbose_flag && ! have_progout) { // callback_add(recog, CALLBACK_EVENT_PASS1_FRAME, frame_indicator, data); // } callback_add(recog, CALLBACK_RESULT_PASS1_INTERIM, result_pass1_current_loader, data); callback_add(recog, CALLBACK_RESULT_PASS1, result_pass1_loader, data); //#ifdef WORD_GRAPH // callback_add(recog, CALLBACK_RESULT_PASS1_GRAPH, result_pass1_graph, data); //#endif // callback_add(recog, CALLBACK_EVENT_PASS1_END, status_pass1_end, data); // callback_add(recog, CALLBACK_STATUS_PARAM, status_param, data); // callback_add(recog, CALLBACK_EVENT_PASS2_BEGIN, status_pass2_begin, data); // callback_add(recog, CALLBACK_EVENT_PASS2_END, status_pass2_end, data); callback_add(recog, CALLBACK_RESULT, result_pass2_loader, data); // rejected, failed // callback_add(recog, CALLBACK_RESULT_GMM, result_gmm, data); // /* below will be called when "-lattice" is specified */ // callback_add(recog, CALLBACK_RESULT_GRAPH, result_graph, data); // /* below will be called when "-confnet" is specified */ // callback_add(recog, CALLBACK_RESULT_CONFNET, result_confnet, data); // // //callback_add_adin(CALLBACK_ADIN_CAPTURED, levelmeter, data); }
void *op_file( struct Brick *brick) { t_context *C=ctx_get(); void *data = op_file_get_data( brick, "image"); if( data) { callback_add( C, op_object_image_load, data); } return NULL; }
void setup_output_file(Recog *recog, void *data) { callback_add(recog, CALLBACK_EVENT_RECOGNITION_BEGIN, outfile_open, data); callback_add(recog, CALLBACK_EVENT_RECOGNITION_END, outfile_close, data); callback_add(recog, CALLBACK_RESULT, outfile_sentence, data); callback_add(recog, CALLBACK_RESULT_GMM, outfile_gmm, data); callback_add(recog, CALLBACK_RESULT_GRAPH, outfile_graph, data); callback_add(recog, CALLBACK_RESULT_CONFNET, outfile_confnet, data); }
/** * <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[]) { Recog *recog; Jconf *jconf; int ret; int i; boolean is_continues; /* create instance */ recog = j_recog_new(); jconf = j_jconf_new(); recog->jconf = jconf; /********************/ /* setup parameters */ /********************/ /* register additional options */ j_add_option("-in", 1, 1, "input from", opt_in); j_add_option("-out", 1, 1, "output to", opt_out); j_add_option("-server", 1, 1, "hostname (-out adinnet)", opt_server); j_add_option("-NA", 1, 1, "NetAudio server host:unit (-in netaudio)", opt_NA); j_add_option("-port", 1, 1, "port number (-out adinnet)", opt_port); j_add_option("-inport", 1, 1, "port number (-in adinnet)", opt_inport); j_add_option("-filename", 1, 1, "(base) filename to record (-out file)", opt_filename); j_add_option("-startid", 1, 1, "recording start id (-out file)", opt_startid); j_add_option("-freq", 1, 1, "sampling frequency in Hz", opt_freq); j_add_option("-nosegment", 0, 0, "not segment input speech, record all", opt_nosegment); j_add_option("-segment", 0, 0, "force segment input speech", opt_segment); j_add_option("-oneshot", 0, 0, "exit after the first input", opt_oneshot); j_add_option("-raw", 0, 0, "save in raw (BE) format", opt_raw); j_add_option("-autopause", 0, 0, "automatically pause at each input end", opt_autopause); j_add_option("-loosesync", 0, 0, "loose sync of resume among servers", opt_loosesync); j_add_option("-rewind", 1, 1, "rewind to the msec", opt_rewind); j_add_option("-h", 0, 0, "display this help", opt_help); j_add_option("-help", 0, 0, "display this help", opt_help); j_add_option("--help", 0, 0, "display this help", opt_help); /* when no argument, output help and exit */ if (argc <= 1) { opt_help(jconf, NULL, 0); return 0; } /* read arguments and set parameters */ if (j_config_load_args(jconf, argc, argv) == -1) { fprintf(stderr, "Error reading arguments\n"); return -1; } /* check needed arguments */ if (speech_output == SPOUT_FILE && filename == NULL) { fprintf(stderr, "Error: output filename not specified\n"); return(-1); } if (speech_output == SPOUT_ADINNET && adinnet_servnum < 1) { fprintf(stderr, "Error: adinnet server name for output not specified\n"); return(-1); } if (jconf->input.speech_input == SP_ADINNET && speech_output != SPOUT_ADINNET && adinnet_servnum >= 1) { fprintf(stderr, "Warning: you specified port num by -port, but it's for output\n"); fprintf(stderr, "Warning: you may specify input port by -inport instead.\n"); fprintf(stderr, "Warning: now the default value (%d) will be used\n", ADINNET_PORT); } #ifdef USE_NETAUDIO if (jconf->input.speech_input == SP_NETAUDIO && jconf->input.netaudio_devname == NULL) { fprintf(stderr, "Error: NetAudio server name not specified\n"); return(-1); } #endif if (adinnet_portnum != adinnet_servnum) { /* if only one server, use default */ if (adinnet_servnum == 1) { adinnet_port[0] = ADINNET_PORT; adinnet_portnum = 1; } else { fprintf(stderr, "Error: you should specify both server names and different port for each!\n"); fprintf(stderr, "\tserver:"); for(i=0;i<adinnet_servnum;i++) fprintf(stderr, " %s", adinnet_serv[i]); fprintf(stderr, "\n\tport :"); for(i=0;i<adinnet_portnum;i++) fprintf(stderr, " %d", adinnet_port[i]); fprintf(stderr, "\n"); return(-1); } } /* set Julius default parameters for unspecified acoustic parameters */ apply_para(&(jconf->am_root->analysis.para), &(jconf->am_root->analysis.para_default)); /* set some values */ jconf->input.sfreq = jconf->am_root->analysis.para.smp_freq; jconf->input.period = jconf->am_root->analysis.para.smp_period; jconf->input.frameshift = jconf->am_root->analysis.para.frameshift; jconf->input.framesize = jconf->am_root->analysis.para.framesize; /* disable successive segmentation when no segmentation available */ if (!jconf->detect.silence_cut) continuous_segment = FALSE; /* store sampling rate locally */ sfreq = jconf->am_root->analysis.para.smp_freq; /********************/ /* setup for output */ /********************/ if (speech_output == SPOUT_FILE) { /* allocate work area for output file name */ if (continuous_segment) { outpath = (char *)mymalloc(strlen(filename) + 10); } else { if (use_raw) { outpath = filename; } else { outpath = new_output_filename(filename, ".wav"); } } } else if (speech_output == SPOUT_ADINNET) { /* connect to adinnet server(s) */ for(i=0;i<adinnet_servnum;i++) { fprintf(stderr, "connecting to #%d (%s:%d)...", i+1, adinnet_serv[i], adinnet_port[i]); sd[i] = make_connection(adinnet_serv[i], adinnet_port[i]); if (sd[i] < 0) return 1; /* on error */ fprintf(stderr, "connected\n"); } } else if (speech_output == SPOUT_STDOUT) { /* output to stdout */ fd = 1; fprintf(stderr,"[STDOUT]"); } /**********************/ /* interrupt handling */ /**********************/ if (signal(SIGINT, interrupt_record) == SIG_ERR) { fprintf(stderr, "Warning: signal interruption may collapse output\n"); } if (signal(SIGTERM, interrupt_record) == SIG_ERR) { fprintf(stderr, "Warning: signal interruption may collapse output\n"); } #ifdef SIGPIPE if (signal(SIGPIPE, interrupt_record) == SIG_ERR) { fprintf(stderr, "Warning: signal interruption may collapse output\n"); } #endif #ifdef SIGQUIT if (signal(SIGQUIT, interrupt_record) == SIG_ERR) { fprintf(stderr, "Warning: signal interruption may collapse output\n"); } #endif /***************************/ /* initialize input device */ /***************************/ if (jconf->input.speech_input == SP_ADINNET) { jconf->input.adinnet_port = adinnet_port_in; } if (j_adin_init(recog) == FALSE) { fprintf(stderr, "Error in initializing adin device\n"); return -1; } if (rewind_msec > 0) { /* allow adin module to keep triggered speech while pausing */ #ifdef HAVE_PTHREAD if (recog->adin->enable_thread) { recog->adin->ignore_speech_while_recog = FALSE; } #endif } /*********************/ /* add some callback */ /*********************/ callback_add(recog, CALLBACK_EVENT_SPEECH_START, record_trigger_time, NULL); /**************************************/ /* display input/output configuration */ /**************************************/ put_status(recog); /*******************/ /* begin recording */ /*******************/ if (continuous_segment) { /* reset parameter for successive output */ total_speechlen = 0; sid = startid; } fprintf(stderr,"[start recording]\n"); if (jconf->input.speech_input == SP_RAWFILE) file_counter = 0; /*********************/ /* input stream loop */ /*********************/ while(1) { /* begin A/D input of a stream */ ret = j_open_stream(recog, NULL); switch(ret) { case 0: /* succeeded */ break; case -1: /* error */ /* go on to next input */ continue; case -2: /* end of recognition process */ switch(jconf->input.speech_input) { case SP_RAWFILE: fprintf(stderr, "%d files processed\n", file_counter); break; case SP_STDIN: fprintf(stderr, "reached end of input on stdin\n"); break; default: fprintf(stderr, "failed to begin input stream\n"); } /* exit recording */ goto record_end; } /*********************************/ /* do VAD and recording */ /*********************************/ do { /* process one segment with segmentation */ /* for incoming speech input, speech detection and segmentation are performed and, adin_callback_* is called for speech output for each segment block. */ /* adin_go() return when input segmented by long silence, or input stream reached to the end */ speechlen = 0; stop_at_next = FALSE; if (jconf->input.speech_input == SP_MIC) { fprintf(stderr, "<<< please speak >>>"); } if (speech_output == SPOUT_ADINNET) { ret = adin_go(adin_callback_adinnet, adinnet_check_command, recog); } else { ret = adin_go(adin_callback_file, NULL, recog); } /* return value of adin_go: -2: input terminated by pause command from adinnet server -1: input device read error or callback process error 0: paused by input stream (end of file, etc..) >0: detected end of speech segment: by adin-cut, or by callback process (or return value of ad_check (<0) (== not used in this program)) */ /* if PAUSE or TERMINATE command has been received while input, stop_at_next is TRUE here */ switch(ret) { case -2: /* terminated by terminate command from server */ fprintf(stderr, "[terminated by server]\n"); break; case -1: /* device read error or callback error */ fprintf(stderr, "[error]\n"); break; case 0: /* reached to end of input */ fprintf(stderr, "[eof]\n"); break; default: /* input segmented by silence or callback process */ fprintf(stderr, "[segmented]\n"); break; } if (ret == -1) { /* error in input device or callback function, so terminate program here */ return 1; } /*************************/ /* one segment processed */ /*************************/ if (speech_output == SPOUT_FILE) { /* close output files */ if (close_files() == FALSE) return 1; } else if (speech_output == SPOUT_ADINNET) { if (speechlen > 0) { if (ret >= 0 || stop_at_next) { /* segmented by adin-cut or end of stream or server-side command */ /* send end-of-segment ack to client */ adin_send_end_of_segment(); } /* output info */ printf("sent: %d samples (%.2f sec.) [%6d (%5.2fs) - %6d (%5.2fs)]\n", speechlen, (float)speechlen / (float)sfreq, trigger_sample, (float)trigger_sample / (float)sfreq, trigger_sample + speechlen, (float)(trigger_sample + speechlen) / (float)sfreq); } } /*************************************/ /* increment ID and total sample len */ /*************************************/ if (continuous_segment) { total_speechlen += speechlen; sid++; } /***************************************************/ /* with adinnet server, if terminated by */ /* server-side PAUSE command, wait for RESUME here */ /***************************************************/ if (pause_each) { /* pause at each end */ //if (speech_output == SPOUT_ADINNET && speechlen > 0) { if (speech_output == SPOUT_ADINNET) { if (adinnet_wait_command() < 0) { /* command error: terminate program here */ return 1; } } } else { if (speech_output == SPOUT_ADINNET && stop_at_next) { if (adinnet_wait_command() < 0) { /* command error: terminate program here */ return 1; } } } /* loop condition check */ is_continues = FALSE; if (continuous_segment && (ret > 0 || ret == -2)) { is_continues = TRUE; } } while (is_continues); /* to the next segment in this input stream */ /***********************/ /* end of input stream */ /***********************/ adin_end(recog->adin); } /* to the next input stream (i.e. next input file in SP_RAWFILE) */ record_end: if (speech_output == SPOUT_FILE) { if (continuous_segment) { printf("recorded total %d samples (%.2f sec.) segmented to %s.%04d - %s.%04d files\n", total_speechlen, (float)total_speechlen / (float)sfreq, filename, 0, filename, sid-1); } } return 0; }
/** * <JA> * モジュール出力を行うよう関数を登録する. * * </JA> * <EN> * Register output functions to enable module output. * * </EN> */ void setup_output_msock(Recog *recog, void *data) { callback_add(recog, CALLBACK_EVENT_PROCESS_ONLINE, status_process_online, data); callback_add(recog, CALLBACK_EVENT_PROCESS_OFFLINE, status_process_offline, data); //callback_add(recog, CALLBACK_EVENT_STREAM_BEGIN, , data); //callback_add(recog, CALLBACK_EVENT_STREAM_END, , data); callback_add(recog, CALLBACK_EVENT_SPEECH_READY, status_recready, data); callback_add(recog, CALLBACK_EVENT_SPEECH_START, status_recstart, data); callback_add(recog, CALLBACK_EVENT_SPEECH_STOP, status_recend, data); callback_add(recog, CALLBACK_EVENT_PASS1_BEGIN, status_pass1_begin, data); callback_add(recog, CALLBACK_EVENT_PASS1_END, status_pass1_end, data); callback_add(recog, CALLBACK_RESULT_PASS1_INTERIM, result_pass1_current, data); callback_add(recog, CALLBACK_RESULT_PASS1, result_pass1_final, data); callback_add(recog, CALLBACK_STATUS_PARAM, status_param, data); callback_add(recog, CALLBACK_RESULT, result_pass2, data); // rejected, failed callback_add(recog, CALLBACK_RESULT_GMM, result_gmm, data); /* below will not be called if "-graphout" not specified */ callback_add(recog, CALLBACK_RESULT_GRAPH, result_graph, data); //callback_add(recog, CALLBACK_EVENT_PAUSE, status_pause, data); //callback_add(recog, CALLBACK_EVENT_RESUME, status_resume, data); }
int main(int argc, char *argv[]) { FILE *fp; Recog *recog; Jconf *jconf; /* inihibit system log output (default: stdout) */ //jlog_set_output(NULL); /* output system log to a file */ // FILE *fp = fopen(logfile, "w"); jlog_set_output(fp); /* if no option argument, output julius usage and exit */ if (argc == 1) { fprintf(stderr, "Julius rev.%s - based on ", JULIUS_VERSION); j_put_version(stderr); fprintf(stderr, "Try '-setting' for built-in engine configuration.\n"); fprintf(stderr, "Try '-help' for run time options.\n"); return -1; } /* add application options */ record_add_option(); module_add_option(); charconv_add_option(); j_add_option("-separatescore", 0, 0, "output AM and LM scores separately", opt_separatescore); j_add_option("-logfile", 1, 1, "output log to file", opt_logfile); j_add_option("-nolog", 0, 0, "not output any log", opt_nolog); j_add_option("-outfile", 0, 0, "save result in separate .out file", opt_outfile); j_add_option("-help", 0, 0, "display this help", opt_help); j_add_option("--help", 0, 0, "display this help", opt_help); /* create a configuration variables container */ jconf = j_jconf_new(); // j_config_load_file(jconf, jconffile); if (j_config_load_args(jconf, argc, argv) == -1) { fprintf(stderr, "Try `-help' for more information.\n"); return -1; } /* output system log to a file */ if (nolog) { jlog_set_output(NULL); } else if (logfile) { fp = fopen(logfile, "w"); jlog_set_output(fp); } /* here you can set/modify any parameter in the jconf before setup */ // jconf->input.input_speech = SP_MIC; /* Fixate jconf parameters: it checks whether the jconf parameters are suitable for recognition or not, and set some internal parameters according to the values for recognition. Modifying a value in jconf after this function may be errorous. */ if (j_jconf_finalize(jconf) == FALSE) { if (logfile) fclose(fp); return -1; } /* create a recognition instance */ recog = j_recog_new(); /* assign configuration to the instance */ recog->jconf = jconf; /* load all files according to the configurations */ if (j_load_all(recog, jconf) == FALSE) { fprintf(stderr, "ERROR: Error in loading model\n"); if (logfile) fclose(fp); return -1; } #ifdef USER_LM_TEST { PROCESS_LM *lm; for(lm=recog->lmlist;lm;lm=lm->next) { if (lm->lmtype == LM_PROB) { j_regist_user_lm_func(lm, my_uni, my_bi, my_lm); } } #endif /* checkout for recognition: build lexicon tree, allocate cache */ if (j_final_fusion(recog) == FALSE) { fprintf(stderr, "ERROR: Error while setup work area for recognition\n"); j_recog_free(recog); if (logfile) fclose(fp); return -1; } /* Set up some application functions */ /* set character conversion mode */ if (charconv_setup() == FALSE) { if (logfile) fclose(fp); return -1; } if (is_module_mode()) { /* set up for module mode */ /* register result output callback functions to network module */ module_setup(recog, NULL); } else { /* register result output callback functions to stdout */ setup_output_tty(recog, NULL); } /* if -outfile option specified, callbacks for file output will be regitered */ if (outfile_enabled) { if (jconf->input.speech_input == SP_MFCFILE || jconf->input.speech_input == SP_RAWFILE) { setup_output_file(recog, NULL); } else { fprintf(stderr, "Warning: -outfile works only for file input, disabled now\n"); outfile_enabled = FALSE; } } /* setup recording if option was specified */ record_setup(recog, NULL); /* on module connect with client */ if (is_module_mode()) module_server(); /* initialize and standby the specified audio input source */ /* for microphone or other threaded input, ad-in thread starts here */ if (j_adin_init(recog) == FALSE) return; /* output system information to log */ j_recog_info(recog); #ifdef VISUALIZE /* Visualize: initialize GTK */ visual_init(recog); callback_add(recog, CALLBACK_EVENT_RECOGNITION_END, visual_show, NULL); callback_add(recog, CALLBACK_EVENT_PASS2_BEGIN, visual2_init, NULL); callback_add(recog, CALLBACK_DEBUG_PASS2_POP, visual2_popped, NULL); callback_add(recog, CALLBACK_DEBUG_PASS2_PUSH, visual2_next_word, NULL); /* below should be called at result */ visual2_best(now, winfo); /* 音声取り込みはコールバックで新規作成 */ /* 第2パスで認識結果出力時に以下を実行 */ visual2_best(now, recog->model->winfo); #endif /* if no grammar specified on startup, start with pause status */ { RecogProcess *r; boolean ok_p; ok_p = TRUE; for(r=recog->process_list;r;r=r->next) { if (r->lmtype == LM_DFA) { if (r->lm->winfo == NULL) { /* stop when no grammar found */ j_request_pause(recog); } } } } /* enter recongnition loop */ main_recognition_stream_loop(recog); /* end proc */ if (is_module_mode()) module_disconnect(); /* release all */ j_recog_free(recog); if (logfile) fclose(fp); return(0); }
int main(int argc, char* argv[]) { // Jconf: configuration parameters // load configurations from command arguments Jconf *jconf = j_config_load_args_new(argc, argv); if (jconf == NULL) { std::cout << "Error @ j_config_load_args_new" << std::endl; return -1; } // Recog: Top level instance for the whole recognition process // create recognition instance according to the jconf Recog *recog = j_create_instance_from_jconf(jconf); if (recog == NULL) { std::cout << "Error @ j_create_instance_from_jconf" << std::endl; return -1; } // Regster callback callback_add(recog, CALLBACK_EVENT_SPEECH_READY, [](Recog *recog, void*) { std::cout << "<<< PLEASE SPEAK! >>>" << std::endl; }, NULL); callback_add(recog, CALLBACK_EVENT_SPEECH_START, [](Recog *recog, void*) { std::cout << "...SPEECH START..." << std::endl; }, NULL); callback_add(recog, CALLBACK_RESULT, [](Recog *recog, void*) { for (const RecogProcess *r = recog->process_list; r; r = r->next) { WORD_INFO *winfo = r->lm->winfo; for (int n = 0; n < r->result.sentnum; ++n) { Sentence *s = &(r->result.sent[n]); WORD_ID *seq = s->word; int seqnum = s->word_num; for (int i = 0; i < seqnum; ++i) { std::cout << winfo->woutput[seq[i]]; } } } }, NULL); // Initialize audio input if (j_adin_init(recog) == FALSE) { return -1; } // output system information to log j_recog_info(recog); // Open input stream and recognize switch (j_open_stream(recog, NULL)) { case 0: break; // success case -1: std::cout << "Error in input stream" << std::endl; return -1; case -2: std::cout << "Failed to begin input stream" << std::endl; return -1; } // Recognition loop int ret = j_recognize_stream(recog); if (ret == -1) return -1; // exit j_close_stream(recog); j_recog_free(recog); return 0; }
//======================== // Create engine instance //======================== bool cJulius::createEngine( void ) { #ifdef APP_ADIN ADIn *a; #endif if (!m_jconf) return false; if (m_recog) return false; #ifdef APP_ADIN if (m_appsource != 0) { switch(m_appsource) { case 1: // buffer input, batch m_recog->jconf->input.type = INPUT_WAVEFORM; m_recog->jconf->input.speech_input = SP_RAWFILE; m_recog->jconf->decodeopt.realtime_flag = FALSE; break; case 2: // buffer input, incremental m_recog->jconf->input.type = INPUT_WAVEFORM; m_recog->jconf->input.speech_input = SP_RAWFILE; m_recog->jconf->decodeopt.realtime_flag = TRUE; break; } } #endif // Create engine instance m_recog = j_create_instance_from_jconf(m_jconf); if (m_recog == NULL) { return false; } // Register callbacks callback_add(m_recog, CALLBACK_EVENT_PROCESS_ONLINE, ::callback_engine_active, this); callback_add(m_recog, CALLBACK_EVENT_PROCESS_OFFLINE, ::callback_engine_inactive, this); callback_add(m_recog, CALLBACK_EVENT_SPEECH_READY, ::callback_audio_ready, this); callback_add(m_recog, CALLBACK_EVENT_SPEECH_START, ::callback_audio_begin, this); callback_add(m_recog, CALLBACK_EVENT_SPEECH_STOP, ::callback_audio_end, this); callback_add(m_recog, CALLBACK_EVENT_RECOGNITION_BEGIN, ::callback_recog_begin, this); callback_add(m_recog, CALLBACK_EVENT_RECOGNITION_END, ::callback_recog_end, this); callback_add(m_recog, CALLBACK_EVENT_PASS1_FRAME, ::callback_recog_frame, this); callback_add(m_recog, CALLBACK_EVENT_PAUSE, ::callback_engine_pause, this); callback_add(m_recog, CALLBACK_EVENT_RESUME, ::callback_engine_resume, this); callback_add(m_recog, CALLBACK_RESULT, ::callback_result_final, this); callback_add(m_recog, CALLBACK_PAUSE_FUNCTION, ::callback_wait_for_resume, this); #ifdef APP_ADIN // Initialize application side audio input if (m_appsource != 0) { a = m_recog->adin; switch(m_appsource) { case 1: // buffer input, batch a->ad_standby = NULL; a->ad_begin = NULL; a->ad_end = NULL; a->ad_resume = NULL; a->ad_pause = NULL; a->ad_terminate = NULL; a->ad_read = callback_adin_fetch_input; a->ad_input_name = NULL; a->silence_cut_default = FALSE; a->enable_thread = FALSE; break; case 2: // buffer input, incremental a->ad_standby = NULL; a->ad_begin = NULL; a->ad_end = NULL; a->ad_resume = NULL; a->ad_pause = NULL; a->ad_terminate = NULL; a->ad_read = callback_adin_fetch_input; a->ad_input_name = NULL; a->silence_cut_default = FALSE; a->enable_thread = FALSE; break; } a->ds = NULL; a->down_sample = FALSE; if (adin_standby(a, m_recog->jconf->input.sfreq, NULL) == FALSE) return false; if (adin_setup_param(a, m_recog->jconf) == FALSE) return false; a->input_side_segment = FALSE; } else { // Let JuliusLib get audio input if (! j_adin_init( m_recog ) ) return false; } #else if (! j_adin_init( m_recog ) ) return false; #endif return true; }
bool CSimpleReport::doCutPaste(CPoint pt, int op) { CXTPReportSelectedRows* pRows = GetSelectedRows(); if (pRows == NULL) return false; CXTPReportRow* pRow = pRows->GetAt(0); int nRow = 0; if (pRow) nRow = pRows->GetAt(0)->GetIndex(); int n; CMenu menu; if (!menu.CreatePopupMenu()) return false; if ((op & DO_ADD) != 0) { menu.AppendMenu(MF_STRING, 10, "Add New"); menu.AppendMenu(MF_STRING, 13, "Insert"); } if (CanCopy() && (op & DO_COPY) != 0) menu.AppendMenu(MF_STRING, 11, "Copy"); if (CanCut() && (op & DO_CUT) != 0) menu.AppendMenu(MF_STRING, 12, "Delete"); n = menu.TrackPopupMenu(TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_RETURNCMD, pt.x, pt.y, this); menu.DestroyMenu(); switch (n) { case 10: // add case 13: // insert { CXTPReportRecord* pRec = newRec(); if (callback_add) { if (!callback_add(this, pRec)) { delete pRec; return false; } } RowInsert(pRec, (n == 10)); } break; case 11: // copy { pRow = GetFocusedRow(); if (!pRow) return false; CXTPReportRecord* pSource = pRow->GetRecord(); CXTPReportRecord* pTarget = newRec(); if (callback_copy) { if (!callback_copy(this, pSource, pTarget)) { delete pTarget; return false; } } RowInsert(pTarget); } break; case 12: // delete { n = pRows->GetCount(); for (int i = 0; i < n; i++) { if (callback_del) { CXTPReportRecord* pRec = pRows->GetAt(i)->GetRecord(); if (!callback_del(this, pRec)) { return false; } } } for (int i = n - 1; i >= 0; i--) { pRow = pRows->GetAt(i); GetRecords()->RemoveAt(pRow->GetRecord()->GetIndex()); } Populate(); RowSetFocused(nRow); } break; default: return false; } return true; }
xreturn::r<bool> JuliusPlus::JuliusFileStart() { assert(this->recogFile == NULL); assert(this->jconfFile == NULL); const char* argv[]={ "juliusplus" ,"-C" ,"testfile.jconf" }; int argc = sizeof(argv)/sizeof(argv[0]); //julius は C関数だから、const外して char** にするしかない。 this->jconfFile = j_config_load_args_new(argc, (char**)argv); /* else, you can load configurations from a jconf file */ //jconf = j_config_load_file_new(jconf_filename); if (this->jconfFile == NULL) { return xreturn::error("Try `-help' for more information.\n"); } /* 2. create recognition instance according to the jconf */ /* it loads models, setup final parameters, build lexicon and set up work area for recognition */ this->recogFile = j_create_instance_from_jconf(this->jconfFile); if (this->recogFile == NULL) { return xreturn::error("Error in startup(j_create_instance_from_jconf)\n"); } struct _ref{ static void output_result(Recog *recog, void *_this) { ((JuliusPlus*)_this)->OnOutputResultFile(recog); } }; callback_add(this->recogFile, CALLBACK_RESULT, _ref::output_result, this); // Initialize audio input if (j_adin_init(this->recogFile) == FALSE) { return xreturn::error("Error in startup(j_adin_init)\n"); } //以上、準備だけしておいて、 //認識ルーチンは、後から呼びます。 /* int ret = j_open_stream(recogFile, "nano.wav"); if(ret < 0) { return xreturn::error("Error in startup(j_open_stream)\n"); } j_recognize_stream(recogFile); ret = j_open_stream(recogFile, "nano.wav"); if(ret < 0) { return xreturn::error("Error in startup(j_open_stream)\n"); } j_recognize_stream(recogFile); */ return true; }
xreturn::r<bool> JuliusPlus::JuliusStart() { assert(this->recog == NULL); assert(this->jconf == NULL); assert(this->Thread == NULL); const char* argv[]={ "juliusplus" ,"-C" ,"testmic.jconf" }; int argc = sizeof(argv)/sizeof(argv[0]); int ret; //julusはC関数なので、const外して char** にするしかない・・・ this->jconf = j_config_load_args_new(argc, (char**)argv); /* else, you can load configurations from a jconf file */ //jconf = j_config_load_file_new(jconf_filename); if (this->jconf == NULL) { return xreturn::error("Try `-help' for more information.\n"); } /* 2. create recognition instance according to the jconf */ /* it loads models, setup final parameters, build lexicon and set up work area for recognition */ this->recog = j_create_instance_from_jconf(this->jconf); if (this->recog == NULL) { return xreturn::error("Error in startup(j_create_instance_from_jconf)\n"); } struct _ref{ static void status_recready(Recog *recog, void *_this) { ((JuliusPlus*)_this)->OnStatusRecready(recog); } static void status_recstart(Recog *recog, void *_this) { ((JuliusPlus*)_this)->OnStatusRecstart(recog); } static void output_result(Recog *recog, void *_this) { ((JuliusPlus*)_this)->OnOutputResult(recog); } static void record_adin_trigger(Recog *recog, SP16 *speech, int samplenum, void *_this) { ((JuliusPlus*)_this)->OnRecordAdinTrigger(recog,speech,samplenum); } }; callback_add(this->recog, CALLBACK_EVENT_SPEECH_READY, _ref::status_recready, this); callback_add(this->recog, CALLBACK_EVENT_SPEECH_START, _ref::status_recstart, this); callback_add(this->recog, CALLBACK_RESULT, _ref::output_result, this); callback_add_adin(this->recog, CALLBACK_ADIN_TRIGGERED, _ref::record_adin_trigger, this); // Initialize audio input if (j_adin_init(this->recog) == FALSE) { return xreturn::error("Error in startup(j_adin_init)\n"); } //output system information to log //j_recog_info(this->recog); ret = j_open_stream(recog, NULL); if(ret < 0) { return xreturn::error("Error in startup(j_open_stream)\n"); } this->Thread = new boost::thread( [&]() { j_recognize_stream(recog); } ); return true; }
/* Julius_Thread::run: main loop */ void Julius_Thread::run() { char *tmp; char buff[MMDAGENT_MAXBUFLEN]; FILE *fp; if(m_jconf != NULL || m_recog != NULL || m_mmdagent == NULL || m_thread < 0 || m_languageModel == 0 || m_dictionary == 0 || m_acousticModel == 0 || m_triphoneList == 0 || m_configFile == 0) return; /* set latency */ sprintf(buff, "PA_MIN_LATENCY_MSEC=%d", JULIUSTHREAD_LATENCY); putenv(buff); sprintf(buff, "LATENCY_MSEC=%d", JULIUSTHREAD_LATENCY); putenv(buff); /* turn off log */ jlog_set_output(NULL); /* load models */ tmp = MMDAgent_pathdup(m_languageModel); sprintf(buff, "-d \"%s\"", tmp); free(tmp); m_jconf = j_config_load_string_new(buff); if (m_jconf == NULL) { return; } tmp = MMDAgent_pathdup(m_dictionary); sprintf(buff, "-v \"%s\"", tmp); free(tmp); if(j_config_load_string(m_jconf, buff) < 0) { return; } tmp = MMDAgent_pathdup(m_acousticModel); sprintf(buff, "-h \"%s\"", tmp); free(tmp); if(j_config_load_string(m_jconf, buff) < 0) { return; } tmp = MMDAgent_pathdup(m_triphoneList); sprintf(buff, "-hlist \"%s\"", tmp); free(tmp); if(j_config_load_string(m_jconf, buff) < 0) { return; } /* load config file */ tmp = MMDAgent_pathdup(m_configFile); if(j_config_load_file(m_jconf, tmp) < 0) { free(tmp); return; } free(tmp); /* load user dictionary */ fp = MMDAgent_fopen(m_userDictionary, "r"); if(fp != NULL) { fclose(fp); tmp = MMDAgent_pathdup(m_userDictionary); j_add_dict(m_jconf->lm_root, tmp); free(tmp); } /* create instance */ m_recog = j_create_instance_from_jconf(m_jconf); if (m_recog == NULL) { return; } /* register callback functions */ callback_add(m_recog, CALLBACK_EVENT_RECOGNITION_BEGIN, callbackRecogBegin, this); callback_add(m_recog, CALLBACK_RESULT, callbackRecogResult, this); if (!j_adin_init(m_recog)) { return; } if (j_open_stream(m_recog, NULL) != 0) { return; } /* setup logger */ m_logger.setup(m_recog); /* start logger */ m_logger.setActiveFlag(true); /* start recognize */ j_recognize_stream(m_recog); }