Julius 4.2
julius/recogloop.c
説明を見る。
00001 
00018 /*
00019  * Copyright (c) 1991-2011 Kawahara Lab., Kyoto University
00020  * Copyright (c) 1997-2000 Information-technology Promotion Agency, Japan
00021  * Copyright (c) 2000-2005 Shikano Lab., Nara Institute of Science and Technology
00022  * Copyright (c) 2005-2011 Julius project team, Nagoya Institute of Technology
00023  * All rights reserved
00024  */
00025 
00026 #include "app.h"
00027 
00028 extern boolean outfile_enabled;
00029 
00030 void
00031 main_recognition_stream_loop(Recog *recog)
00032 {
00033   Jconf *jconf;
00034   int file_counter;
00035   int ret;
00036   FILE *mfclist;
00037   static char speechfilename[MAXPATHLEN];       /* pathname of speech file or MFCC file */
00038   
00039   jconf = recog->jconf;
00040 
00041   /* reset file count */
00042   file_counter = 0;
00043   
00044   if (jconf->input.speech_input == SP_MFCFILE) {
00045     if (jconf->input.inputlist_filename != NULL) {
00046       /* open filelist for mfc input */
00047       if ((mfclist = fopen(jconf->input.inputlist_filename, "r")) == NULL) { /* open error */
00048         fprintf(stderr, "Error: cannot open inputlist \"%s\"\n", jconf->input.inputlist_filename);
00049         return;
00050       }
00051     }
00052   }
00053       
00054   /**********************************/
00056   /**********************************/
00057   for (;;) {
00058 
00059     printf("\n");
00060     if (verbose_flag) printf("------\n");
00061     fflush(stdout);
00062 
00063     /*********************/
00064     /* open input stream */
00065     /*********************/
00066     if (jconf->input.speech_input == SP_MFCFILE) {
00067       /* from MFCC parameter file (in HTK format) */
00068       VERMES("### read analyzed parameter\n");
00069       if (jconf->input.inputlist_filename != NULL) {    /* has filename list */
00070         do {
00071           if (getl_fp(speechfilename, MAXPATHLEN, mfclist) == NULL) {
00072             fclose(mfclist);
00073             fprintf(stderr, "%d files processed\n", file_counter);
00074 #ifdef REPORT_MEMORY_USAGE
00075             print_mem();
00076 #endif
00077             return;
00078           }
00079         } while (speechfilename[0] == '\0' || speechfilename[0] == '#');
00080       } else {
00081         if (get_line_from_stdin(speechfilename, MAXPATHLEN, "enter MFCC filename->") == NULL) {
00082           fprintf(stderr, "%d files processed\n", file_counter);
00083 #ifdef REPORT_MEMORY_USAGE
00084           print_mem();
00085 #endif
00086           return;
00087         }
00088       }
00089       if (verbose_flag) printf("\ninput MFCC file: %s\n", speechfilename);
00090       if (outfile_enabled) outfile_set_fname(speechfilename);
00091 
00092       /* open stream */
00093       ret = j_open_stream(recog, speechfilename);
00094       switch(ret) {
00095       case 0:                   /* succeeded */
00096         break;
00097       case -1:                  /* error */
00098         /* go on to the next input */
00099         continue;
00100       case -2:                  /* end of recognition */
00101         return;
00102       }
00103 
00104       /* start recognizing the stream */
00105       do {
00106 
00107         ret = j_recognize_stream(recog);
00108 
00109         switch(ret) {
00110         case 1:       /* paused by callback (stream may continues) */
00111           /* do whatever you want while stopping recognition */
00112 
00113           /* after here, recognition will restart */
00114           break;
00115         case 0:                 /* end of stream */
00116           /* go on to the next input */
00117           break;
00118         case -1:                /* error */
00119           return;
00120         }
00121       } while (ret == 1);
00122           
00123       /* count number of processed files */
00124       file_counter++;
00125 
00126     } else {                    /* raw speech input */
00127 
00128       VERMES("### read waveform input\n");
00129       /* begin A/D input */
00130       ret = j_open_stream(recog, NULL);
00131       switch(ret) {
00132       case 0:                   /* succeeded */
00133         break;
00134       case -1:                  /* error */
00135         /* go on to next input */
00136         continue;
00137       case -2:                  /* end of recognition process */
00138         if (jconf->input.speech_input == SP_RAWFILE) {
00139           fprintf(stderr, "%d files processed\n", file_counter);
00140         } else if (jconf->input.speech_input == SP_STDIN) {
00141           fprintf(stderr, "reached end of input on stdin\n");
00142         } else {
00143           fprintf(stderr, "failed to begin input stream\n");
00144         }
00145         return;
00146       }
00147       if (outfile_enabled) {
00148         outfile_set_fname(j_get_current_filename(recog));
00149       }
00150       /* start recognizing the stream */
00151       ret = j_recognize_stream(recog);
00152       /* how to stop:
00153          add a function to CALLBACK_POLL and call j_request_pause() or
00154          j_request_terminate() in the function.
00155          Julius will them stop search and call CALLBACK_PAUSE_FUNCTION.
00156          after all callbacks in CALLBACK_PAUSE_FUNCTION was processed,
00157          Julius resume the search.
00158       */
00159       if (ret == -1) {          /* error */
00160         return;
00161       }
00162       /* else, end of stream */
00163       
00164       /* count number of processed files */
00165       if (jconf->input.speech_input == SP_RAWFILE) {
00166         file_counter++;
00167       }
00168     }
00169   }
00170 
00171 }