Пример #1
0
/**
 * <EN>
 * Create a new configuration instance and load parameters from a jconf
 * file.
 * </EN>
 * <JA>
 * 新たな設定インスタンスを割り付け,そこに
 * jconfファイルから設定パラメータを読み込んで返す.
 * </JA>
 *
 * @param filename [in] jconf filename
 *
 * @return the newly allocated global configuration instance.
 *
 * @callgraph
 * @callergraph
 * @ingroup jconf
 */
Jconf *
j_config_load_file_new(char *filename)
{
    Jconf *jconf;
    jconf = j_jconf_new();
    if (j_config_load_file(jconf, filename) == -1) {
        j_jconf_free(jconf);
        return NULL;
    }
    return jconf;
}
Пример #2
0
/**
 * <EN>
 * Create a new configuration instance and load parameters from string
 * file.
 * </EN>
 * <JA>
 * 新たな設定インスタンスを割り付け,そこに
 * 文字列から設定パラメータを読み込んで返す.
 * </JA>
 *
 * @param string [in] option string
 *
 * @return the newly allocated global configuration instance.
 *
 * @callgraph
 * @callergraph
 * @ingroup jconf
 */
Jconf *
j_config_load_string_new(char *string)
{
    Jconf *jconf;
    jconf = j_jconf_new();
    if (j_config_load_string(jconf, string) == -1) {
        j_jconf_free(jconf);
        return NULL;
    }
    return jconf;
}
Пример #3
0
/**
 * <EN>
 * Create a new configuration instance and load parameters from command
 * argments.
 * </EN>
 * <JA>
 * コマンド引数からパラメータを読み込み,その値を格納した
 * 新たな設定インスタンスを割り付けて返す.
 * </JA>
 *
 * @param argc [in] number of arguments
 * @param argv [in] list of argument strings
 *
 * @return the newly allocated global configuration instance.
 *
 * @callgraph
 * @callergraph
 * @ingroup jconf
 */
Jconf *
j_config_load_args_new(int argc, char *argv[])
{
    Jconf *jconf;
    jconf = j_jconf_new();
    if (j_config_load_args(jconf, argc, argv) == -1) {
        j_jconf_free(jconf);
        return NULL;
    }
    return jconf;
}
Пример #4
0
/** 
 * <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;
}
Пример #5
0
int
main(int argc, char *argv[])
{
  Recog *recog;
  Jconf *jconf;
  float *ss;
  MFCCWork *wrk;

  /* create instance */
  recog = j_recog_new();
  jconf = j_jconf_new();
  recog->jconf = jconf;

  /* set application-specific additional options */
  j_add_option("-freq", 1, 1, "sampling freq in Hz", opt_freq);
  j_add_option("-len", 1, 1, "record length in msec", opt_len);
  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;
  }

  /* regard last arg as filename */
  if (strmatch(argv[argc-1], "-")) {
    stout = TRUE;
  } else {
    filename = argv[argc-1];
  }

  /* set default as same as "-input mic" */
  jconf->input.type = INPUT_WAVEFORM;
  jconf->input.speech_input = SP_MIC;
  jconf->input.device = SP_INPUT_DEFAULT;
  /* process config and load them */
  if (j_config_load_args(jconf, argc-1, argv) == -1) {
    fprintf(stderr, "Error reading arguments\n");
    return -1;
  }
  /* force some default values */
  jconf->detect.silence_cut  = 0; /* disable silence cut */
  jconf->preprocess.strip_zero_sample = TRUE; /* strip zero samples */
  jconf->detect.level_thres = 0;	/* no VAD, record all */
  /* 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;

  sfreq = jconf->am_root->analysis.para.smp_freq;

  /* output 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("mkss");
	return(1);
      }
    }
  }

  /* allocate speech store buffer */
  samples = sfreq * slen / 1000;
  speech = (SP16 *)mymalloc(sizeof(SP16) * samples);

  /* allocate work area to compute spectrum */
  wrk = WMP_work_new(&(jconf->am_root->analysis.para));
  if (wrk == NULL) {
    jlog("ERROR: m_fusion: failed to initialize MFCC computation for SS\n");
    return -1;
  }

  /* initialize input device */
  if (j_adin_init(recog) == FALSE) {
    fprintf(stderr, "Error in initializing adin device\n");
    return -1;
  }

  /* open device */
  if (j_open_stream(recog, NULL) < 0) {
    fprintf(stderr, "Error in opening adin device\n");
  }

  /* record mic input */
  fprintf(stderr, "%dHz recording for %.2f seconds of noise\n", sfreq, (float)slen /(float)1000);
  speechnum = 0;
  adin_go(adin_callback, NULL, recog);

  /* close device */
  adin_end(recog->adin);
  fprintf(stderr, "\n%d samples (%d bytes, %.1f sec) recorded\n", samples, samples * sizeof(SP16), (float)samples / (float)sfreq);

  /* compute SS */
  fprintf(stderr, "compute SS:\n");
  fprintf(stderr, "  fsize : %4d samples (%.1f msec)\n", jconf->input.framesize, (float)jconf->input.framesize * 1000.0/ (float)sfreq);
  fprintf(stderr, "  fshift: %4d samples (%.1f msec)\n", jconf->input.frameshift, (float)jconf->input.frameshift * 1000.0/ (float)sfreq);

  ss = new_SS_calculate(speech, samples, &sslen, wrk, &(jconf->am_root->analysis.para));

  fprintf(stderr, "  points: %4d\n", sslen);
  fprintf(stderr, "noise spectrum was measured\n");
  
  /* open file for recording */
  fprintf(stderr, "writing average noise spectrum to [%s]...", filename);
  if (stout) {
    fd = 1;
  } else {
    if ((fd = open(filename, O_CREAT | O_RDWR
#ifdef O_BINARY
		   | O_BINARY
#endif
		   , 0644)) == -1) {
      perror("mkss");
      return(1);
    }
  }
  x = sslen;
#ifndef WORDS_BIGENDIAN
  swap_bytes((char *)&x, sizeof(int), 1);
#endif
  if (write(fd, &x, sizeof(int)) < sizeof(int)) {
    perror("mkss");
    return(1);
  }
#ifndef WORDS_BIGENDIAN
  swap_bytes((char *)ss, sizeof(float), sslen);
#endif
  if (write(fd, ss, sslen * sizeof(float)) < sslen * sizeof(float)) {
    perror("mkss");
    return(1);
  }
  if (!stout) {
    if (close(fd) < 0) {
      perror("mkss");
      return(1);
    }
  }
  fprintf(stderr, "done\n");

  WMP_free(wrk);

  return 0;
}
int cTumkwsjSink::setupJulius()
{
  try {

    int argc=3;
    char* argv[3] = {"julius","-C",NULL};
    if (configfile != NULL)
      argv[2]=strdup(configfile);
    else
      argv[2]=strdup("kws.cfg");

    /* add application option dummies */
    /*
    j_add_option("-gprob", 1, 1, "garbage probability", opt_gprob);
    j_add_option("-kprob", 1, 1, "keyword probability", opt_kprob);
    j_add_option("-knum", 1, 1, "number of keywords", opt_knum);
    */  

    /* create a configuration variables container */
    jconf = j_jconf_new();
    //    j_config_load_file(jconf, strdup(configfile));
    if (j_config_load_args(jconf, argc, argv) == -1) {
      COMP_ERR("error parsing julius decoder options, this might be a bug. see tumkwsjSink.cpp!");
      j_jconf_free(jconf);
      free(argv[2]);
      return 0;
    }
    free(argv[2]);

    /* output system log to a file */
    if (getInt("debug") != 1) {
      jlog_set_output(NULL);
    }

    /* here you can set/modify any parameter in the jconf before setup */
    jconf->input.type = INPUT_VECTOR;
    jconf->input.speech_input = SP_EXTERN;
    jconf->decodeopt.realtime_flag = TRUE; // ??? 
    jconf->ext.period = (float)(reader->getLevelT());
    jconf->ext.veclen = reader->getLevelN();
    jconf->ext.userptr = (void *)this;
    jconf->ext.fv_read = external_fv_read_loader;

    /* 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) {
      SMILE_IERR(1,"error finalising julius jconf in setupJulius()!");
      j_jconf_free(jconf);
      return 0;
    }

    /* create a recognition instance */
    recog = j_recog_new();
    /* use user-definable data hook to set a pointer to our class instance */
    recog->hook = (void *)this;
    /* assign configuration to the instance */
    recog->jconf = jconf;
    /* load all files according to the configurations */
    if (j_load_all(recog, jconf) == FALSE) {
      SMILE_IERR(1, "Error in loading model for Julius decoder");
      j_recog_free(recog);
      return 0;
    }

    SMILE_IMSG(2,"garbage prob.: %f",glogprob);
    SMILE_IMSG(2,"keyword prob.: %f",klogprob);
    SMILE_IMSG(2,"number of phonemes: %i",numphon);

    // register user LM, get vocab size, and init lmWeights with zero or load from file
    PROCESS_LM *lm; 
    for(lm=recog->lmlist;lm;lm=lm->next) {
      if (lm->lmtype == LM_PROB) {
        lm->winfo->userptr = (void*)this;  // PATCH: sent/vocabulary.h (WORD_INFO struct): ++   void * userptr;   // Pointer to userdata....
        j_regist_user_lm_func(lm, userlm_uni_loader, userlm_bi_loader, userlm_lm_loader);
        if ((numWords==0)&&((long)(lm->winfo->num)>0)) {
          lmWinfo = lm->winfo;
          numWords = (long)(lm->winfo->num);
        }
      }
    }

    // load lmWeights data:
    //printf("XXX HEREA");
    if (dynamicLm) {
      //printf("XXX HERE0");
      if (lmWinfo != NULL) {
        //printf("XXX HERE");
        lmWeights = (LOGPROB*)malloc(sizeof(LOGPROB)*numWords);
        if (lmWeights == NULL) { OUT_OF_MEMORY; }
        int i;
        for (i=0; i<numWords; i++) { lmWeights[i] = (LOGPROB)lmpenalty; }
        const char *lmfile = getStr("lmfile");
        if (lmfile != NULL) {
          FILE *lf=fopen(lmfile,"r");
          if (lf == NULL) { SMILE_IERR(1,"Error opening word weights file (lmfile) '%s'",lmfile); }
          else  {
            SMILE_IMSG(1,"lmfile: '%s'",lmfile);
            long lineNr = 0;
            char *line=NULL; size_t len=0;
            size_t r=-1;
            do {      
              r = getline(&line, &len, lf);
              //printf("XXX LINE '%s'",line);
              if ((r != (size_t)-1)&&(line!=NULL)) {
                lineNr++;
                parseLmWeightsLine(line,lineNr,lmfile);
              } 
            } while (r != (size_t)-1);
          }
        }

      } else { 
        SMILE_IERR(1,"no language model word info (vocabulary) found, check julius config!"); 
      }
    }
    //----

    /* 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 0;
    }

    setupCallbacks(recog, NULL);

    /* output system information to log */
    j_recog_info(recog);

    terminated = FALSE;

  }
  catch (int) { }

  juliusIsSetup=1;

  return 1;
}
Пример #7
0
/** 
 * <JA>
 * ヘルプを表示する. 
 * 
 * </JA>
 * <EN>
 * Output help document.
 * 
 * </EN>
 *
 * @param fp [in] file pointer to output help
 *
 * @callgraph
 * @callergraph
 * @ingroup engine
 * 
 */
void
j_output_argument_help(FILE *fp)
{
  Jconf *jconf;
#ifdef ENABLE_PLUGIN
  int id;
  char buf[64];
  PLUGIN_ENTRY *p;
  FUNC_VOID func;
#endif
    
  /* load default values */
  jconf = j_jconf_new();

  j_put_header(fp);
  j_put_compile_defs(fp);
  fprintf(fp, "\nOptions:\n");

  fprintf(fp, "\n--- Global Options -----------------------------------------------\n");

  fprintf(fp, "\n Speech Input:\n");
  fprintf(fp, "    (Can extract only MFCC based features from waveform)\n");
  fprintf(fp, "    [-input devname]    input source  (default = htkparam)\n");
  fprintf(fp, "         htkparam/mfcfile  HTK parameter file\n");
  fprintf(fp, "         file/rawfile      waveform file (%s)\n", SUPPORTED_WAVEFILE_FORMAT);
#ifdef USE_MIC
  fprintf(fp, "         mic               default microphone device\n");
# ifdef HAS_ALSA
  fprintf(fp, "         alsa              use ALSA interface\n");
# endif
# ifdef HAS_OSS
  fprintf(fp, "         oss               use OSS interface\n");
# endif
# ifdef HAS_ESD
  fprintf(fp, "         esd               use ESounD interface\n");
# endif
#endif
#ifdef USE_NETAUDIO
  fprintf(fp, "         netaudio          DatLink/NetAudio server\n");
#endif
  fprintf(fp, "         adinnet           adinnet client (TCP/IP)\n");
  fprintf(fp, "         stdin             standard input\n");
#ifdef ENABLE_PLUGIN
  if (global_plugin_list) {
    if ((id = plugin_get_id("adin_get_optname")) >= 0) {
      for(p=global_plugin_list[id];p;p=p->next) {
	func = (FUNC_VOID) p->func;
	(*func)(buf, (int)64);
	fprintf(fp, "         %-18s(adin plugin #%d)\n", buf, p->source_id);
      }
    }
    if ((id = plugin_get_id("fvin_get_optname")) >= 0) {
      for(p=global_plugin_list[id];p;p=p->next) {
	func = (FUNC_VOID) p->func;
	(*func)(buf, (int)64);
	fprintf(fp, "         %-18s(feature vector input plugin #%d)\n", buf, p->source_id);
      }
    }
  }
#endif
  fprintf(fp, "    [-filelist file]    filename of input file list\n");
#ifdef USE_NETAUDIO
  fprintf(fp, "    [-NA host:unit]     get audio from NetAudio server at host:unit\n");
#endif
  fprintf(fp, "    [-adport portnum]   adinnet port number to listen         (%d)\n", jconf->input.adinnet_port);
  fprintf(fp, "    [-48]               enable 48kHz sampling with internal down sampler (OFF)\n");
  fprintf(fp, "    [-zmean/-nozmean]   enable/disable DC offset removal      (OFF)\n");
  fprintf(fp, "    [-nostrip]          disable stripping off zero samples\n");
  fprintf(fp, "    [-record dir]       record triggered speech data to dir\n");
  fprintf(fp, "    [-rejectshort msec] reject an input shorter than specified\n");
#ifdef POWER_REJECT
  fprintf(fp, "    [-powerthres value] rejection threshold of average power  (%.1f)\n", jconf->reject.powerthres);
#endif
  
  fprintf(fp, "\n Speech Detection: (default: on=mic/net off=files)\n");
  /*fprintf(fp, "    [-pausesegment]     turn on (force) pause detection\n");*/
  /*fprintf(fp, "    [-nopausesegment]   turn off (force) pause detection\n");*/
  fprintf(fp, "    [-cutsilence]       turn on (force) skipping long silence\n");
  fprintf(fp, "    [-nocutsilence]     turn off (force) skipping long silence\n");
  fprintf(fp, "    [-lv unsignedshort] input level threshold (0-32767)       (%d)\n", jconf->detect.level_thres);
  fprintf(fp, "    [-zc zerocrossnum]  zerocross num threshold per sec.      (%d)\n", jconf->detect.zero_cross_num);
  fprintf(fp, "    [-headmargin msec]  header margin length in msec.         (%d)\n", jconf->detect.head_margin_msec);
  fprintf(fp, "    [-tailmargin msec]  tail margin length in msec.           (%d)\n", jconf->detect.tail_margin_msec);

  fprintf(fp, "\n GMM utterance verification:\n");
  fprintf(fp, "    -gmm filename       GMM definition file\n");
  fprintf(fp, "    -gmmnum num         GMM Gaussian pruning num              (%d)\n", jconf->reject.gmm_gprune_num);
  fprintf(fp, "    -gmmreject string   comma-separated list of noise model name to reject\n");
#ifdef GMM_VAD
  fprintf(fp, "\n GMM-based VAD:\n");
  fprintf(fp, "    -gmmmargin frames   backstep margin on speech trigger     (%d)\n", jconf->detect.gmm_margin);
  fprintf(fp, "    -gmmup score        up-trigger threshold                  (%.1f)\n", jconf->detect.gmm_uptrigger_thres);
  fprintf(fp, "    -gmmdown score      down-trigger threshold                (%.1f)\n", jconf->detect.gmm_downtrigger_thres);
#endif

  fprintf(fp, "\n On-the-fly Decoding: (default: on=mic/net off=files)\n");
  fprintf(fp, "    [-realtime]         turn on, input streamed with MAP-CMN\n");
  fprintf(fp, "    [-norealtime]       turn off, input buffered with sentence CMN\n");

  fprintf(fp, "\n Others:\n");
  fprintf(fp, "    [-C jconffile]      load options from jconf file\n");
  fprintf(fp, "    [-quiet]            reduce output to only word string\n");
  fprintf(fp, "    [-demo]             equal to \"-quiet -progout\"\n");
  fprintf(fp, "    [-debug]            (for debug) dump numerous log\n");
  fprintf(fp, "    [-callbackdebug]    (for debug) output message per callback\n");
  fprintf(fp, "    [-check (wchmm|trellis)] (for debug) check internal structure\n");
  fprintf(fp, "    [-check triphone]   triphone mapping check\n");
  fprintf(fp, "    [-setting]          print engine configuration and exit\n");
  fprintf(fp, "    [-help]             print this message and exit\n");

  fprintf(fp, "\n--- Instance Declarations ----------------------------------------\n\n");

  fprintf(fp, "    [-AM]               start a new acoustic model instance\n");
  fprintf(fp, "    [-LM]               start a new language model instance\n");
  fprintf(fp, "    [-SR]               start a new recognizer (search) instance\n");
  fprintf(fp, "    [-AM_GMM]           start an AM feature instance for GMM\n");
  fprintf(fp, "    [-GLOBAL]           start a global section\n");
  fprintf(fp, "    [-nosectioncheck]   disable option location check\n");
  fprintf(fp, "\n--- Acoustic Model Options (-AM) ---------------------------------\n");

  fprintf(fp, "\n Acoustic analysis:\n");
  fprintf(fp, "    [-htkconf file]     load parameters from the HTK Config file\n");
  fprintf(fp, "    [-smpFreq freq]     sample period (Hz)                    (%ld)\n", jconf->am_root->analysis.para_default.smp_freq);
  fprintf(fp, "    [-smpPeriod period] sample period (100ns)                 (%ld)\n", jconf->am_root->analysis.para_default.smp_period);
  fprintf(fp, "    [-fsize sample]     window size (sample)                  (%d)\n", jconf->am_root->analysis.para_default.framesize);
  fprintf(fp, "    [-fshift sample]    frame shift (sample)                  (%d)\n", jconf->am_root->analysis.para_default.frameshift);
  fprintf(fp, "    [-preemph]          pre-emphasis coef.                    (%.2f)\n", jconf->am_root->analysis.para_default.preEmph);
  fprintf(fp, "    [-fbank]            number of filterbank channels         (%d)\n", jconf->am_root->analysis.para_default.fbank_num);
  fprintf(fp, "    [-ceplif]           cepstral liftering coef.              (%d)\n", jconf->am_root->analysis.para_default.lifter);
  fprintf(fp, "    [-rawe] [-norawe]   toggle using raw energy               (no)\n");
  fprintf(fp, "    [-enormal] [-noenormal] toggle normalizing log energy     (no)\n");
  fprintf(fp, "    [-escale]           scaling log energy for enormal        (%.1f)\n", jconf->am_root->analysis.para_default.escale);
  fprintf(fp, "    [-silfloor]         energy silence floor in dB            (%.1f)\n", jconf->am_root->analysis.para_default.silFloor);
  fprintf(fp, "    [-delwin frame]     delta windows length (frame)          (%d)\n", jconf->am_root->analysis.para_default.delWin);
  fprintf(fp, "    [-accwin frame]     accel windows length (frame)          (%d)\n", jconf->am_root->analysis.para_default.accWin);
  fprintf(fp, "    [-hifreq freq]      freq. of upper band limit, off if <0  (%d)\n", jconf->am_root->analysis.para_default.hipass);
  fprintf(fp, "    [-lofreq freq]      freq. of lower band limit, off if <0  (%d)\n", jconf->am_root->analysis.para_default.lopass);
  fprintf(fp, "    [-sscalc]           do spectral subtraction (file input only)\n");
  fprintf(fp, "    [-sscalclen msec]   length of head silence for SS (msec)  (%d)\n", jconf->am_root->frontend.sscalc_len);
  fprintf(fp, "    [-ssload filename]  load constant noise spectrum from file for SS\n");
  fprintf(fp, "    [-ssalpha value]    alpha coef. for SS                    (%f)\n", jconf->am_root->frontend.ss_alpha);
  fprintf(fp, "    [-ssfloor value]    spectral floor for SS                 (%f)\n", jconf->am_root->frontend.ss_floor);
  fprintf(fp, "    [-zmeanframe/-nozmeanframe] frame-wise DC removal like HTK(OFF)\n");
  fprintf(fp, "    [-usepower/-nousepower] use power in fbank analysis       (OFF)\n");
  fprintf(fp, "    [-cmnload file]     load initial CMN param from file on startup\n");
  fprintf(fp, "    [-cmnsave file]     save CMN param to file after each input\n");
  fprintf(fp, "    [-cmnnoupdate]      not update CMN param while recog. (use with -cmnload)\n");
  fprintf(fp, "    [-cmnmapweight]     weight value of initial cm for MAP-CMN (%6.2f)\n", jconf->am_root->analysis.cmn_map_weight);
  fprintf(fp, "    [-cvn]              cepstral variance normalisation       (%s)\n", jconf->amnow->analysis.para.cvn ? "on" : "off");
  fprintf(fp, "    [-vtln alpha lowcut hicut] enable VTLN (1.0 to disable)   (%f)\n", jconf->am_root->analysis.para_default.vtln_alpha);

  fprintf(fp, "\n Acoustic Model:\n");
  fprintf(fp, "    -h hmmdefsfile      HMM definition file name\n");
  fprintf(fp, "    [-hlist HMMlistfile] HMMlist filename (must for triphone model)\n");
  fprintf(fp, "    [-iwcd1 methodname] switch IWCD triphone handling on 1st pass\n");
  fprintf(fp, "             best N     use N best score (default of n-gram, N=%d)\n", jconf->am_root->iwcdmaxn);
  fprintf(fp, "             max        use maximum score\n");
  fprintf(fp, "             avg        use average score (default of dfa)\n");
  fprintf(fp, "    [-force_ccd]        force to handle IWCD\n");
  fprintf(fp, "    [-no_ccd]           don't handle IWCD\n");
  fprintf(fp, "    [-notypecheck]      don't check input parameter type\n");
  fprintf(fp, "    [-spmodel HMMname]  name of short pause model             (\"%s\")\n", SPMODEL_NAME_DEFAULT);
  fprintf(fp, "    [-multipath]        switch decoding for multi-path HMM    (auto)\n");

  fprintf(fp, "\n Acoustic Model Computation Method:\n");
  fprintf(fp, "    [-gprune methodname] select Gaussian pruning method:\n");
#ifdef GPRUNE_DEFAULT_SAFE
  fprintf(fp, "             safe          safe pruning (default for TM/PTM)\n");
#else
  fprintf(fp, "             safe          safe pruning\n");
#endif
#if GPRUNE_DEFAULT_HEURISTIC
  fprintf(fp, "             heuristic     heuristic pruning (default for TM/PTM)\n");
#else
  fprintf(fp, "             heuristic     heuristic pruning\n");
#endif
#if GPRUNE_DEFAULT_BEAM
  fprintf(fp, "             beam          beam pruning (default for TM/PTM)\n");
#else
  fprintf(fp, "             beam          beam pruning\n");
#endif
  fprintf(fp, "             none          no pruning (default for non tmix models)\n");
#ifdef ENABLE_PLUGIN
  if (global_plugin_list) {
    if ((id = plugin_get_id("calcmix_get_optname")) >= 0) {
      for(p=global_plugin_list[id];p;p=p->next) {
	func = (FUNC_VOID) p->func;
	(*func)(buf, (int)64);
	fprintf(fp, "             %-14s(calculation plugin #%d)\n", buf, p->source_id);
      }
    }
  }
#endif
  fprintf(fp, "    [-tmix gaussnum]    Gaussian num threshold per mixture for pruning (%d)\n", jconf->am_root->mixnum_thres);
  fprintf(fp, "    [-gshmm hmmdefs]    monophone hmmdefs for GS\n");
  fprintf(fp, "    [-gsnum N]          N-best state will be selected        (%d)\n", jconf->am_root->gs_statenum);

  fprintf(fp, "\n--- Language Model Options (-LM) ---------------------------------\n");

  fprintf(fp, "\n N-gram:\n");
  fprintf(fp, "    -d file.bingram     n-gram file in Julius binary format\n");
  fprintf(fp, "    -nlr file.arpa      forward n-gram file in ARPA format\n");
  fprintf(fp, "    -nrl file.arpa      backward n-gram file in ARPA format\n");
  fprintf(fp, "    [-lmp float float]  weight and penalty (tri: %.1f %.1f mono: %.1f %1.f)\n", DEFAULT_LM_WEIGHT_TRI_PASS1, DEFAULT_LM_PENALTY_TRI_PASS1, DEFAULT_LM_WEIGHT_MONO_PASS1, DEFAULT_LM_PENALTY_MONO_PASS1);
  fprintf(fp, "    [-lmp2 float float]       for 2nd pass (tri: %.1f %.1f mono: %.1f %1.f)\n", DEFAULT_LM_WEIGHT_TRI_PASS2, DEFAULT_LM_PENALTY_TRI_PASS2, DEFAULT_LM_WEIGHT_MONO_PASS2, DEFAULT_LM_PENALTY_MONO_PASS2);
  fprintf(fp, "    [-transp float]     penalty for transparent word (%+2.1f)\n", jconf->search_root->lmp.lm_penalty_trans);

  fprintf(fp, "\n DFA Grammar:\n");
  fprintf(fp, "    -dfa file.dfa       DFA grammar file\n");
  fprintf(fp, "    -gram file[,file2...] (list of) grammar prefix(es)\n");
  fprintf(fp, "    -gramlist filename  filename of grammar list\n");
  fprintf(fp, "    [-penalty1 float]   word insertion penalty (1st pass)     (%.1f)\n", jconf->search_root->lmp.penalty1);
  fprintf(fp, "    [-penalty2 float]   word insertion penalty (2nd pass)     (%.1f)\n", jconf->search_root->lmp.penalty2);

  fprintf(fp, "\n Word Dictionary for N-gram and DFA:\n");
  fprintf(fp, "    -v dictfile         dictionary file name\n");
  fprintf(fp, "    [-silhead wordname] (n-gram) beginning-of-sentence word   (%s)\n", BEGIN_WORD_DEFAULT);
  fprintf(fp, "    [-siltail wordname] (n-gram) end-of-sentence word         (%s)\n", END_WORD_DEFAULT);
  fprintf(fp, "    [-mapunk wordname]  (n-gram) map unknown words to this    (%s)\n", UNK_WORD_DEFAULT);
  fprintf(fp, "    [-forcedict]        ignore error entry and keep running\n");
  fprintf(fp, "    [-iwspword]         (n-gram) add short-pause word for inter-word CD sp\n");
  fprintf(fp, "    [-iwspentry entry]  (n-gram) word entry for \"-iwspword\" (%s)\n", IWSPENTRY_DEFAULT);
  
  fprintf(fp, "\n Isolated Word Recognition:\n");
  fprintf(fp, "    -w file[,file2...]  (list of) wordlist file name(s)\n");
  fprintf(fp, "    -wlist filename     file that contains list of wordlists\n");
  fprintf(fp, "    -wsil head tail sp  name of silence/pause model\n");
  fprintf(fp, "                          head - BOS silence model name       (%s)\n", jconf->lm_root->wordrecog_head_silence_model_name);
  fprintf(fp, "                          tail - EOS silence model name       (%s)\n", jconf->lm_root->wordrecog_tail_silence_model_name);
  fprintf(fp, "                           sp  - their name as context or \"NULL\" (%s)\n", (jconf->lm_root->wordrecog_silence_context_name[0] == '\0') ? "NULL" : jconf->lm_root->wordrecog_silence_context_name);
#ifdef DETERMINE
  fprintf(fp, "    -wed float int      thresholds for early word determination\n");
  fprintf(fp, "                        float: score threshold    (%.1f)\n", jconf->search_root->pass1.determine_score_thres);
  fprintf(fp, "                        int: frame duration thres (%d)\n", jconf->search_root->pass1.determine_duration_thres);
#endif

  fprintf(fp, "\n--- Recognizer / Search Options (-SR) ----------------------------\n");


  fprintf(fp, "\n Search Parameters for the First Pass:\n");
  fprintf(fp, "    [-b beamwidth]      beam width (by state num)             (guessed)\n");
  fprintf(fp, "                        (0: full search, -1: force guess)\n");
#ifdef WPAIR
# ifdef WPAIR_KEEP_NLIMIT
  fprintf(fp, "    [-nlimit N]         keeps only N tokens on each state     (%d)\n", jconf->search_root->pass1.wpair_keep_nlimit);
# endif
#endif
#ifdef SEPARATE_BY_UNIGRAM
  fprintf(fp, "    [-sepnum wordnum]   (n-gram) # of hi-freq word isolated from tree (%d)\n", jconf->lm_root->separate_wnum);
#endif
#ifdef HASH_CACHE_IW
  fprintf(fp, "    [-iwcache percent]  (n-gram) amount of inter-word LM cache (%3d)\n", jconf->search_root->pass1.iw_cache_rate);
#endif
  fprintf(fp, "    [-1pass]            do 1st pass only, omit 2nd pass\n");
  fprintf(fp, "    [-inactive]         recognition process not active on startup\n");

  fprintf(fp, "\n Search Parameters for the Second Pass:\n");
  fprintf(fp, "    [-b2 hyponum]       word envelope beam width (by hypo num) (%d)\n",jconf->search_root->pass2.enveloped_bestfirst_width);
  fprintf(fp, "    [-n N]              # of sentence to find                 (%d)\n", jconf->search_root->pass2.nbest);
  fprintf(fp, "    [-output N]         # of sentence to output               (%d)\n",jconf->search_root->output.output_hypo_maxnum);
#ifdef SCAN_BEAM
  fprintf(fp, "    [-sb score]         score beam threshold (by score)       (%.1f)\n", jconf->search_root->pass2.scan_beam_thres);
#endif
  fprintf(fp, "    [-s hyponum]        global stack size of hypotheses       (%d)\n", jconf->search_root->pass2.stack_size);
  fprintf(fp, "    [-m hyponum]        hypotheses overflow threshold num     (%d)\n", jconf->search_root->pass2.hypo_overflow);

  fprintf(fp, "    [-lookuprange N]    frame lookup range in word expansion  (%d)\n", jconf->search_root->pass2.lookup_range);
  fprintf(fp, "    [-looktrellis]      (dfa) expand only backtrellis words\n");
  fprintf(fp, "    [-[no]multigramout] (dfa) output per-grammar results\n");
  fprintf(fp, "    [-oldtree]          (dfa) use old build_wchmm()\n");
#ifdef PASS1_IWCD
  fprintf(fp, "    [-oldiwcd]          (dfa) use full lcdset\n");
#endif
  fprintf(fp, "    [-iwsp]             insert sp for all word end (multipath)(off)\n");
  fprintf(fp, "    [-iwsppenalty]      trans. penalty for iwsp (multipath)   (%.1f)\n", jconf->am_root->iwsp_penalty);

  fprintf(fp, "\n Short-pause Segmentation:\n");
  fprintf(fp, "    [-spsegment]        enable short-pause segmentation\n");
  fprintf(fp, "    [-spdur]            length threshold of sp frames         (%d)\n", jconf->search_root->successive.sp_frame_duration);
#ifdef SPSEGMENT_NAIST
  fprintf(fp, "    [-spmargin]         backstep margin on speech trigger     (%d)\n", jconf->search_root->successive.sp_margin);
  fprintf(fp, "    [-spdelay]          delay on speech trigger               (%d)\n", jconf->search_root->successive.sp_delay);
#endif
  fprintf(fp, "    [-pausemodels str]  comma-delimited list of pause models for segment\n");

  fprintf(fp, "\n Graph Output with graph-oriented search:\n");
  fprintf(fp, "    [-lattice]          enable word graph (lattice) output\n");
  fprintf(fp, "    [-confnet]          enable confusion network output\n");
  fprintf(fp, "    [-nolattice]][-noconfnet] disable lattice / confnet output\n");
  fprintf(fp, "    [-graphrange N]     merge same words in graph (%d)\n", jconf->search_root->graph.graph_merge_neighbor_range);
  fprintf(fp, "                        -1: not merge, leave same loc. with diff. score\n");
  fprintf(fp, "                         0: merge same words at same location\n");
  fprintf(fp, "                        >0: merge same words around the margin\n");
#ifdef GRAPHOUT_DEPTHCUT
  fprintf(fp, "    [-graphcut num]     graph cut depth at postprocess (-1: disable)(%d)\n", jconf->search_root->graph.graphout_cut_depth);
#endif
#ifdef GRAPHOUT_LIMIT_BOUNDARY_LOOP
  fprintf(fp, "    [-graphboundloop num] max. num of boundary adjustment loop (%d)\n", jconf->search_root->graph.graphout_limit_boundary_loop_num);
#endif
#ifdef GRAPHOUT_SEARCH_DELAY_TERMINATION
  fprintf(fp, "    [-graphsearchdelay] inhibit search termination until 1st sent. found\n");
  fprintf(fp, "    [-nographsearchdelay] disable it (default)\n");
#endif

  fprintf(fp, "\n Forced Alignment:\n");
  fprintf(fp, "    [-walign]           optionally output word alignments\n");
  fprintf(fp, "    [-palign]           optionally output phoneme alignments\n");
  fprintf(fp, "    [-salign]           optionally output state alignments\n");
#ifdef CONFIDENCE_MEASURE
  fprintf(fp, "\n Confidence Score:\n");
#ifdef CM_MULTIPLE_ALPHA
  fprintf(fp, "    [-cmalpha f t s]    CM smoothing factor        (from, to, step)\n");
#else
  fprintf(fp, "    [-cmalpha value]    CM smoothing factor                    (%f)\n", jconf->search_root->annotate.cm_alpha);
#endif
#ifdef CM_SEARCH_LIMIT
  fprintf(fp, "    [-cmthres value]    CM threshold to cut hypo on 2nd pass   (%f)\n", jconf->search_root->annotate.cm_cut_thres);
#endif
#endif /* CONFIDENCE_MEASURE */
  fprintf(fp, "\n Message Output:\n");
  fprintf(fp, "    [-fallback1pass]    use 1st pass result when search failed\n");
  fprintf(fp, "    [-progout]          progressive output in 1st pass\n");
  fprintf(fp, "    [-proginterval]     interval of progout in msec           (%d)\n", jconf->search_root->output.progout_interval);

  fprintf(fp, "\n-------------------------------------------------\n");

  j_jconf_free(jconf);

  /* output application-side options */
  useropt_show_desc(fp);

}
Пример #8
0
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);
}
Пример #9
0
/** 
 * <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;

  /* create instance */
  jconf = j_jconf_new();

  /* register application options */
  j_add_option("-freq", 1, 1, "sampling frequency in Hz", opt_freq);
  j_add_option("-raw", 0, 0, "save in raw (BE) format", opt_raw);
  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;
  }

  /* regard last arg as filename */
  if (strmatch(argv[argc-1], "-")) {
    stout = TRUE;
    use_raw = TRUE;
  } else {
    filename = argv[argc-1];
  }

  /* set default as same as "-input mic" */
  jconf->input.type = INPUT_WAVEFORM;
  jconf->input.speech_input = SP_MIC;
  jconf->input.device = SP_INPUT_DEFAULT;

  /* read arguments and set parameters */
  if (j_config_load_args(jconf, argc-1, argv) == -1) {
    fprintf(stderr, "Error reading arguments\n");
    return -1;
  }

  /* exit if no file name specified */
  if (filename == NULL && stout == FALSE) {
    opt_help(jconf, NULL, 0);
    return -1;
  }

  /* finalize config */
  //if (j_jconf_finalize(jconf) == FALSE) 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;

  /* preliminary check of output file */
  /* (output file will be opened later when input is triggered) */
  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);
      }
    }
  }
  /* set signal handlers to properly close output file */
  if (signal(SIGINT, interrupt_record) == SIG_ERR) {
    fprintf(stderr, "Warning: signal intterupt may collapse output\n");
  }
  if (signal(SIGTERM, interrupt_record) == SIG_ERR) {
    fprintf(stderr, "Warning: signal intterupt may collapse output\n");
  }
#ifdef SIGPIPE
  if (signal(SIGPIPE, interrupt_record) == SIG_ERR) {
    fprintf(stderr, "Warning: signal intterupt may collapse output\n");
  }
#endif
#ifdef SIGQUIT
  if (signal(SIGQUIT, interrupt_record) == SIG_ERR) {
    fprintf(stderr, "Warning: signal intterupt may collapse output\n");
  }
#endif

  recog = j_recog_new();
  recog->jconf = jconf;

  /* initialize input device */
  if (j_adin_init(recog) == FALSE) {
    fprintf(stderr, "Error in initializing adin device\n");
    return -1;
  }
  /* open device */
  if (j_open_stream(recog, NULL) < 0) {
    fprintf(stderr, "Error in opening adin device\n");
  }
  /* do recoding */
  speechlen = 0;
  sfreq = recog->jconf->input.sfreq;
  fprintf(stderr, "<<< please speak >>>"); /* moved from adin-cut.c */
  adin_go(adin_callback_file, NULL, recog);
  /* close device */
  adin_end(recog->adin);
  /* close output file */
  close_file();

  return 0;
}