/** 
 * <JA>
 * 発話検証・棄却用の1状態 GMM を読み込んで初期化する. 
 * 
 * </JA>
 * <EN>
 * Read and initialize an 1-state GMM for utterance verification and
 * rejection.
 * 
 * </EN>
 *
 * @param jconf [in] global configuration variables
 *
 * @return the newly created GMM information structure in HMM format,
 * or NULL on failure.
 */
static HTK_HMM_INFO *
initialize_GMM(Jconf *jconf)
{
  HTK_HMM_INFO *gmm;
  
  jlog("STAT: reading GMM: %s\n", jconf->reject.gmm_filename);

  if (jconf->gmm == NULL) {
    /* no acoustic parameter setting was given for GMM using -AM_GMM, 
       copy the first AM setting */
    jlog("STAT: -AM_GMM not used, use parameter of the first AM\n");
    jconf->gmm = j_jconf_am_new();
    memcpy(jconf->gmm, jconf->am_root, sizeof(JCONF_AM));
    jconf->gmm->hmmfilename = NULL;
    jconf->gmm->mapfilename = NULL;
    jconf->gmm->spmodel_name = NULL;
    jconf->gmm->hmm_gs_filename = NULL;
    if (jconf->am_root->analysis.cmnload_filename) {
      jconf->gmm->analysis.cmnload_filename = strcpy((char *)mymalloc(strlen(jconf->am_root->analysis.cmnload_filename)+ 1), jconf->am_root->analysis.cmnload_filename);
    }
    if (jconf->am_root->analysis.cmnsave_filename) {
      jconf->gmm->analysis.cmnsave_filename = strcpy((char *)mymalloc(strlen(jconf->am_root->analysis.cmnsave_filename)+ 1), jconf->am_root->analysis.cmnsave_filename);
    }
    if (jconf->am_root->frontend.ssload_filename) {
      jconf->gmm->frontend.ssload_filename = strcpy((char *)mymalloc(strlen(jconf->am_root->frontend.ssload_filename)+ 1), jconf->am_root->frontend.ssload_filename);
    }
  }

  gmm = hmminfo_new();
  if (init_hmminfo(gmm, jconf->reject.gmm_filename, NULL, &(jconf->gmm->analysis.para_hmm)) == FALSE) {
    hmminfo_free(gmm);
    return NULL;
  }
  /* check parameter type of this acoustic HMM */
  if (jconf->input.type == INPUT_WAVEFORM) {
    /* Decode parameter extraction type according to the training
       parameter type in the header of the given acoustic HMM */
    switch(gmm->opt.param_type & F_BASEMASK) {
    case F_MFCC:
    case F_FBANK:
    case F_MELSPEC:
      break;
    default:
      jlog("ERROR: m_fusion: for direct speech input, only GMM trained by MFCC ior filterbank is supported\n");
      hmminfo_free(gmm);
      return NULL;
    }
  }

  /* set acoustic analysis parameters from HMM header */
  calc_para_from_header(&(jconf->gmm->analysis.para), gmm->opt.param_type, gmm->opt.vec_size);

  if (jconf->gmm->analysis.para_htk.loaded == 1) apply_para(&(jconf->gmm->analysis.para), &(jconf->gmm->analysis.para_htk));
  if (jconf->gmm->analysis.para_hmm.loaded == 1) apply_para(&(jconf->gmm->analysis.para), &(jconf->gmm->analysis.para_hmm));
  apply_para(&(jconf->gmm->analysis.para), &(jconf->gmm->analysis.para_default));

  return(gmm);
}
Exemple #2
0
/** 
 * <JA>
 * Gaussian Mixture Selection のための状態選択用モノフォンHMMを読み込む. 
 * </JA>
 * <EN>
 * Initialize context-independent HMM for state selection with Gaussian
 * Mixture Selection.
 * </EN>
 *
 * @param amconf [in] AM configuratino variables
 *
 * @return the newly created HMM information structure, or NULL on failure.
 */
static HTK_HMM_INFO *
initialize_GSHMM(JCONF_AM *amconf)
{
  HTK_HMM_INFO *hmm_gs;
  Value para_dummy;

  jlog("STAT: Reading GS HMMs:\n");
  hmm_gs = hmminfo_new();
  undef_para(&para_dummy);
  if (init_hmminfo(hmm_gs, amconf->hmm_gs_filename, NULL, &para_dummy) == FALSE) {
    hmminfo_free(hmm_gs);
    return NULL;
  }
  return(hmm_gs);
}
Exemple #3
0
int
main(int argc, char *argv[])
{
  FILE *fp;
  char *hmmdefs_file;
  char *hmmlist_file;
  char *outfile;
  int i;

  hmmdefs_file = hmmlist_file = outfile = NULL;
  for(i=1;i<argc;i++) {
    if (hmmdefs_file == NULL) {
      hmmdefs_file = argv[i];
    } else if (hmmlist_file == NULL) {
      hmmlist_file = argv[i];
    } else if (outfile == NULL) {
      outfile = argv[i];
    } else {
      usage(argv[0]);
      return -1;
    }
  }
  if (hmmdefs_file == NULL || hmmlist_file == NULL || outfile == NULL) {
    usage(argv[0]);
    return -1;
  }

  hmminfo = hmminfo_new();

  printf("---- reading hmmdefs ----\n");
  printf("filename: %s\n", hmmdefs_file);

  /* read hmmdef file */
  undef_para(&para);
  if (init_hmminfo(hmminfo, hmmdefs_file, hmmlist_file, &para) == FALSE) {
    fprintf(stderr, "--- terminated\n");
    return -1;
  }

  if (hmminfo->is_triphone) {
    fprintf(stderr, "making pseudo bi/mono-phone for IW-triphone\n");
    if (make_cdset(hmminfo) == FALSE) {
      fprintf(stderr, "ERROR: m_fusion: failed to make context-dependent state set\n");
      return -1;
    }
  }

  printf("\n------------------------------------------------------------\n");
  print_hmmdef_info(stdout, hmminfo);
  printf("\n");

  printf("------------------------------------------------------------\n");

  printf("---- writing logical-to-physical mapping and pseudo phone info ----\n");
  printf("filename: %s\n", outfile);

  if ((fp = fopen_writefile(outfile)) == NULL) {
    fprintf(stderr, "failed to open %s for writing\n", outfile);
    return -1;
  }
  if (save_hmmlist_bin(fp, hmminfo) == FALSE) {
    fprintf(stderr, "failed to write to %s\n", outfile);
    return -1;
  }
  if (fclose_writefile(fp) != 0) {
    fprintf(stderr, "failed to close %s\n", outfile);
    return -1;
  }

  printf("\n");
  printf("binary HMMList and pseudo phone definitions are written to \"%s\"\n", outfile);

  return 0;
}
Exemple #4
0
/** 
 * <JA>
 * @brief  音響HMMをファイルから読み込み,認識用にセットアップする. 
 *
 * ファイルからのHMM定義の読み込み,HMMList ファイルの読み込み,
 * パラメータ型のチェック,マルチパス扱いの on/off, ポーズモデルの設定など
 * が行われ,認識のための準備が行われる. 
 *
 * この音響モデルの入力となる音響パラメータの種類やパラメータもここで
 * 最終決定される. 決定には,音響HMMのヘッダ,(バイナリHMMの場合,存
 * 在すれば)バイナリHMMに埋め込まれた特徴量情報,jconf の設定(ばらば
 * らに,あるいは -htkconf 使用時)などの情報が用いられる. 
 * </JA>
 * <EN>
 * @brief  Read in an acoustic HMM from file and setup for recognition.
 *
 * This functions reads HMM definitions from file, reads also a
 * HMMList file, makes logical-to-physical model mapping, determine
 * required parameter type, determine whether multi-path handling is needed,
 * and find pause model in the definitions.
 *
 * The feature vector extraction parameters are also finally
 * determined in this function.  Informations used for the
 * determination is (1) the header values in hmmdefs, (2) embedded
 * parameters in binary HMM if you are reading a binary HMM made with
 * recent mkbinhmm, (3) user-specified parameters in jconf
 * configurations (either by separatedly specified or by -htkconf
 * options).
 *
 * </EN>
 * 
 * @param amconf [in] AM configuration variables
 * @param jconf [i/o] global configuration variables
 * 
 * @return the newly created HMM information structure, or NULL on failure.
 * 
 */
static HTK_HMM_INFO *
initialize_HMM(JCONF_AM *amconf, Jconf *jconf)
{
  HTK_HMM_INFO *hmminfo;

  /* at here, global variable "para" holds values specified by user or
     by user-specified HTK config file */
  if (amconf->analysis.para_hmm.loaded == 1) {
    jlog("Warning: you seems to read more than one acoustic model for recognition, but\n");
    jlog("Warning: previous one already has header-embedded acoustic parameters\n");
    jlog("Warning: if you have different parameters, result may be wrong!\n");
  }
  
  /* allocate new hmminfo */
  hmminfo = hmminfo_new();
  /* load hmmdefs */
  if (init_hmminfo(hmminfo, amconf->hmmfilename, amconf->mapfilename, &(amconf->analysis.para_hmm)) == FALSE) {
    hmminfo_free(hmminfo);
    return NULL;
  }

  /* set multipath mode flag */
  if (amconf->force_multipath) {
    jlog("STAT: m_fusion: force multipath HMM handling by user request\n");
    hmminfo->multipath = TRUE;
  } else {
    hmminfo->multipath = hmminfo->need_multipath;
  }

  /* only MFCC is supported for audio input */
  /* MFCC_{0|E}[_D][_A][_Z][_N] is supported */
  /* check parameter type of this acoustic HMM */
  if (jconf->input.type == INPUT_WAVEFORM) {
    /* Decode parameter extraction type according to the training
       parameter type in the header of the given acoustic HMM */
    if ((hmminfo->opt.param_type & F_BASEMASK) != F_MFCC) {
      jlog("ERROR: m_fusion: for direct speech input, only HMM trained by MFCC is supported\n");
      hmminfo_free(hmminfo);
      return NULL;
    }
    /* set acoustic analysis parameters from HMM header */
    calc_para_from_header(&(amconf->analysis.para), hmminfo->opt.param_type, hmminfo->opt.vec_size);
  }
  /* check if tied_mixture */
  if (hmminfo->is_tied_mixture && hmminfo->codebooknum <= 0) {
    jlog("ERROR: m_fusion: this tied-mixture model has no codebook!?\n");
    hmminfo_free(hmminfo);
    return NULL;
  }

#ifdef PASS1_IWCD
  /* make state clusters of same context for inter-word triphone approx. */
  if (hmminfo->is_triphone) {
    if (hmminfo->cdset_root == NULL) {
      jlog("STAT: making pseudo bi/mono-phone for IW-triphone\n");
      if (make_cdset(hmminfo) == FALSE) {
	jlog("ERROR: m_fusion: failed to make context-dependent state set\n");
	hmminfo_free(hmminfo);
	return NULL;
      }
    } else {
      jlog("STAT: pseudo phones are loaded from binary hmmlist file\n");
    }

    /* add those `pseudo' biphone and monophone to the logical HMM names */
    /* they points not to the defined HMM, but to the CD_Set structure */
    hmm_add_pseudo_phones(hmminfo);
  }
#endif

  /* find short pause model and set to hmminfo->sp */
  htk_hmm_set_pause_model(hmminfo, amconf->spmodel_name);


  hmminfo->cdset_method = amconf->iwcdmethod;
  hmminfo->cdmax_num = amconf->iwcdmaxn;

  if (amconf->analysis.para_htk.loaded == 1) apply_para(&(amconf->analysis.para), &(amconf->analysis.para_htk));
  if (amconf->analysis.para_hmm.loaded == 1) apply_para(&(amconf->analysis.para), &(amconf->analysis.para_hmm));
  apply_para(&(amconf->analysis.para), &(amconf->analysis.para_default));

  return(hmminfo);
  
}
Exemple #5
0
int
main(int argc, char *argv[])
{
  FILE *fp;
  char *infile;
  char *outfile;
  char *conffile;
  int i;

  infile = outfile = conffile = NULL;
  for(i=1;i<argc;i++) {
    if (strmatch(argv[i], "-C") || strmatch(argv[i], "-htkconf")) {
      if (++i >= argc) {
	usage(argv[0]);
	return -1;
      }
      conffile = argv[i];
    } else {
      if (infile == NULL) {
	infile = argv[i];
      } else if (outfile == NULL) {
	outfile = argv[i];
      } else {
	usage(argv[0]);
	return -1;
      }
    }
  }
  if (infile == NULL || outfile == NULL) {
    usage(argv[0]);
    return -1;
  }

  hmminfo = hmminfo_new();

  printf("---- reading hmmdefs ----\n");
  printf("filename: %s\n", infile);

  /* read hmmdef file */
  undef_para(&para);
  if (init_hmminfo(hmminfo, infile, NULL, &para) == FALSE) {
    fprintf(stderr, "--- terminated\n");
    return -1;
  }

  if (conffile != NULL) {
    /* if input HMMDEFS already has embedded parameter
       they will be overridden by the parameters in the config file */
    printf("\n---- reading HTK Config ----\n");
    if (para.loaded == 1) {
      printf("Warning: input hmmdefs has acoustic analysis parameter information\n");
      printf("Warning: they are overridden by the HTK Config file...\n");
    }
    /* load HTK config file */
    undef_para(&para);
    if (htk_config_file_parse(conffile, &para) == FALSE) {
      fprintf(stderr, "Error: failed to read %s\n", conffile);
      return(-1);
    }
    /* set some parameters from HTK HMM header information */
    printf("\nsetting TARGETKIND and NUMCEPS from HMM definition header...");
    calc_para_from_header(&para, hmminfo->opt.param_type, hmminfo->opt.vec_size);
    printf("done\n");
    /* fulfill unspecified values with HTK defaults */
    printf("fulfill unspecified values with HTK defaults...");
    undef_para(&para_htk);
    make_default_para_htk(&para_htk);
    apply_para(&para, &para_htk);
    printf("done\n");
  }

  printf("\n------------------------------------------------------------\n");
  print_hmmdef_info(stdout, hmminfo);
  printf("\n");

  if (para.loaded == 1) {
    put_para(stdout, &para);
  }
  printf("------------------------------------------------------------\n");

  printf("---- writing ----\n");
  printf("filename: %s\n", outfile);
  
  if ((fp = fopen_writefile(outfile)) == NULL) {
    fprintf(stderr, "failed to open %s for writing\n", outfile);
    return -1;
  }
  if (write_binhmm(fp, hmminfo, (para.loaded == 1) ? &para : NULL) == FALSE) {
    fprintf(stderr, "failed to write to %s\n", outfile);
    return -1;
  }
  if (fclose_writefile(fp) != 0) {
    fprintf(stderr, "failed to close %s\n", outfile);
    return -1;
  }

  printf("\n");
  if (para.loaded == 1) {
    printf("binary HMM written to \"%s\", with acoustic parameters embedded for Julius.\n", outfile);
  } else {
    printf("binary HMM written to \"%s\"\n", outfile);
  }

  return 0;
}