Beispiel #1
0
int
main(int argc, char *argv[])
{
    cmd_ln_parse(defs, orig_argc, orig_argv, TRUE);
    cmd_ln_parse(defs, argc, argv, FALSE);
    printf("%d %s %d %f\n",
           cmd_ln_int32("-a"),
           cmd_ln_str("-b") ? cmd_ln_str("-b") : "(null)",
           cmd_ln_boolean("-c"),
           cmd_ln_float64("-d"));
           
    return 0;
}
Beispiel #2
0
int
parse_cmd_ln(int argc, char *argv[])
{
  uint32      isHelp;
  uint32      isExample;

#include "cmd_ln_defn.h"

    cmd_ln_parse(defn, argc, argv, 1);

    isHelp    = cmd_ln_int32("-help");
    isExample    = cmd_ln_int32("-example");

    if(isHelp){
      printf("%s\n\n",helpstr);
    }

    if(isExample){
      printf("%s\n\n",examplestr);
    }

    if(isHelp || isExample){
      E_INFO("User asked for help or example.\n");
      exit(0);
    }


    return 0;
}
Beispiel #3
0
int
ld_init(live_decoder_t *decoder, int argc, char **argv)
{
  param_t fe_param;

  if (argc == 2) {
    /*
     * lgalescu: check if args need to be processed from file
     */
    parse_args_file(argv[1]);
  } else 
    cmd_ln_parse(arg_def, argc, argv);

  unlimit();
	
  /* some decoder parameter capturing
   * !!! NOTE - HARDCODED FOR NOW.  REPLACE WITH PARSE_ARG() ASAP !!!!
   */
  memset(decoder, 0, sizeof(live_decoder_t));
  kb_init(&decoder->kb);
  decoder->max_wpf = cmd_ln_int32 ("-maxwpf");;
  decoder->max_histpf = cmd_ln_int32 ("-maxhistpf");
  decoder->max_hmmpf = cmd_ln_int32 ("-maxhmmpf");
  decoder->phones_skip = cmd_ln_int32 ("-ptranskip");
  decoder->hmm_log = cmd_ln_int32("-hmmdump") ? stderr : NULL;
	
  decoder->kbcore = decoder->kb.kbcore;
  decoder->kb.uttid = decoder->uttid;
  decoder->hypsegs = 0;
  decoder->num_hypsegs = 0;
  decoder->hypstr_len = 0;
  decoder->hypstr[0] = '\0';
  decoder->features =
    feat_array_alloc(kbcore_fcb(decoder->kbcore), LIVEBUFBLOCKSIZE);
  decoder->ld_state = LD_STATE_IDLE;
	
  /* some front-end parameter capturing
   * !!! NOTE - HARDCODED FOR NOW.  REPLACE WITH PARSE_ARG() ASAP !!!!
   */
  memset(&fe_param, 0, sizeof(param_t));
  fe_param.SAMPLING_RATE = (float32)cmd_ln_int32 ("-samprate");
  fe_param.LOWER_FILT_FREQ = cmd_ln_float32("-lowerf");
  fe_param.UPPER_FILT_FREQ = cmd_ln_float32("-upperf");
  fe_param.NUM_FILTERS = cmd_ln_int32("-nfilt");
  fe_param.FRAME_RATE = cmd_ln_int32("-frate");
  fe_param.PRE_EMPHASIS_ALPHA = cmd_ln_float32("-alpha");
  fe_param.FFT_SIZE = cmd_ln_int32("-nfft");
  fe_param.WINDOW_LENGTH = cmd_ln_float32("-wlen");
	
  decoder->fe = fe_init(&fe_param);
  if (!decoder->fe) {
    E_WARN("Front end initialization fe_init() failed\n");
    return -1;
  }
	
  return 0;
}
int
ld_init_with_args(live_decoder_t * _decoder, int _argc, char **_argv)
{
    assert(_decoder != NULL);

    if (cmd_ln_parse(arg_def, _argc, _argv) != 0) {
        E_WARN("Failed to parse arguments.\n");
        return LD_ERROR_INTERNAL;
    }

    return ld_init_impl(_decoder, TRUE);
}
Beispiel #5
0
static void
gst_pocketsphinx_init (GstPocketSphinx * rec,
		       GstPocketSphinxClass * gclass)
{
    /* Create the hash table to store argument strings. */
    rec->arghash = g_hash_table_new(g_str_hash, g_str_equal);

    /* Parse default command-line options. */
    cmd_ln_parse(fbs_get_args(), default_argc, default_argv, FALSE);

    /* Create an adapter object to "pull" data from the pipeline */
    GST_BASE_SINK(rec)->sync = FALSE;
    rec->adapter = gst_adapter_new ();
}
Beispiel #6
0
void
cmd_ln_appl_enter(int argc, char *argv[],
                  const char *default_argfn,
                  const arg_t * defn)
{
    /* Look for default or specified arguments file */
    const char *str;

    str = NULL;

    if ((argc == 2) && (strcmp(argv[1], "help") == 0)) {
        cmd_ln_print_help(stderr, defn);
        exit(1);
    }

    if ((argc == 2) && (argv[1][0] != '-'))
        str = argv[1];
    else if (argc == 1) {
        FILE *fp;
        E_INFO("Looking for default argument file: %s\n", default_argfn);

        if ((fp = fopen(default_argfn, "r")) == NULL) {
            E_INFO("Can't find default argument file %s.\n",
                   default_argfn);
        }
        else {
            str = default_argfn;
        }
        if (fp != NULL)
            fclose(fp);
    }


    if (str) {
        /* Build command line argument list from file */
        E_INFO("Parsing command lines from file %s\n", str);
        if (cmd_ln_parse_file(defn, str, TRUE)) {
            E_INFOCONT("Usage:\n");
            E_INFOCONT("\t%s argument-list, or\n", argv[0]);
            E_INFOCONT("\t%s [argument-file] (default file: . %s)\n\n",
                    argv[0], default_argfn);
            cmd_ln_print_help(stderr, defn);
            exit(1);
        }
    }
    else {
        cmd_ln_parse(defn, argc, argv, TRUE);
    }
}
Beispiel #7
0
void  parse_args_file(char *live_args)
{
    static char **liveargs;
    static int32 nliveargs;
    int32 nargs, maxarglen;
    char  *argline, *targ; 
    FILE *fp;

    if ((fp = fopen(live_args,"r")) == NULL)
	E_FATAL("Unable to open arguments file %s for reading\n",live_args);

    argline = (char*) ckd_calloc(10000,sizeof(char)); /* Longest line allowed */
    nargs = 1;
    maxarglen = 0;
    while (fgets(argline,10000,fp) != NULL){
        if ((targ = strtok(argline," \t\n")) == NULL)
            continue; /* Empty line in argfile */
	if (strlen(targ) > (unsigned int)maxarglen) maxarglen = strlen(targ);
	nargs++; 

        while ((targ = strtok(NULL," \t\n")) != NULL){
	    if (strlen(targ) > (unsigned int)maxarglen) maxarglen = strlen(targ);
	    nargs++; 
	}
    }
    rewind(fp);

    nliveargs = nargs;
    liveargs = (char**) ckd_calloc_2d(nargs,maxarglen+1,sizeof(char));

    nargs = 1;
    while (fgets(argline,10000,fp) != NULL){
        if ((targ = strtok(argline," \t\n")) == NULL)
            continue; /* Empty line in argfile */

        strcpy(liveargs[nargs++],targ);
        while ((targ = strtok(NULL," \t\n")) != NULL){
            strcpy(liveargs[nargs++],targ);
	}
    }
    fclose(fp);

    assert(nargs == nliveargs);
    free(argline);

    cmd_ln_parse(arg, nliveargs, liveargs);

    return;
}
Beispiel #8
0
main (int32 argc, char *argv[])
{
    char *reffile, *mdeffile, *dictfile, *fdictfile, *homfile;
    
    if (argc == 1) {
	cmd_ln_print_help (stderr, arglist);
	exit(0);
    }
    
    cmd_ln_parse (arglist, argc, argv);
    
    if ((mdeffile = (char *) cmd_ln_access ("-mdef")) == NULL)
	E_FATAL("-mdef argument missing\n");
    if ((dictfile = (char *) cmd_ln_access ("-dict")) == NULL)
	E_FATAL("-dict argument missing\n");
    if ((fdictfile = (char *) cmd_ln_access ("-fdict")) == NULL)
	E_FATAL("-fdict argument missing\n");
    if ((reffile = (char *) cmd_ln_access ("-ref")) == NULL)
	E_FATAL("-ref argument missing\n");

    unlimit();
    
    mdef = mdef_init (mdeffile);
    if (mdef->n_ciphone <= 0)
	E_FATAL("0 CIphones in %s\n", mdeffile);
    
    dict = dict_init (mdef, dictfile, fdictfile);
    oovbegin = dict->n_word;
    
    startwid = dict_wordid (dict, "<s>");
    finishwid = dict_wordid (dict, "</s>");
    silwid = dict_wordid (dict, (char *) cmd_ln_access("-sil"));
    assert (dict_filler_word (dict, silwid));
    
    homlist = NULL;
    if ((homfile = (char *) cmd_ln_access ("-hom")) != NULL)
	homfile_load (homfile);
    
    process_reffile (reffile);
    
#if (0 && (! WIN32))
    fflush (stdout);
    fflush (stderr);
    system ("ps aguxwww | grep dpalign");
#endif

    exit(0);
}
static int32 cmdline_parse (int argc, char *argv[])
{
    int32 i;
    char *logfile;
    
    E_INFO("Parsing command line:\n");
    for (i = 0; i < argc; i++) {
	if (argv[i][0] == '-')
	    printf ("\\\n\t");
	printf ("%s ", argv[i]);
    }
    printf ("\n\n");
    fflush (stdout);

    cmd_ln_parse (argc, argv);

    if (cmd_ln_validate() == FALSE) {
	E_FATAL("Unable to validate command line arguments\n");
    }

    logfp = NULL;
    if ((logfile = (char *)cmd_ln_access("-logfn")) != NULL) {
	if ((logfp = fopen(logfile, "w")) == NULL) {
	    E_ERROR("fopen(%s,w) failed; logging to stdout/stderr\n");
	} else {
	    orig_stdout = *stdout;	/* Hack!! To avoid hanging problem under Linux */
	    orig_stderr = *stderr;	/* Hack!! To avoid hanging problem under Linux */
	    *stdout = *logfp;
	    *stderr = *logfp;
	    
	    E_INFO("Command line:\n");
	    for (i = 0; i < argc; i++) {
		if (argv[i][0] == '-')
		    printf ("\\\n\t");
		printf ("%s ", argv[i]);
	    }
	    printf ("\n\n");
	    fflush (stdout);
	}
    }
    
    E_INFO("Configuration in effect:\n");
    cmd_ln_print_configuration();
    printf ("\n");
    
    return 0;
}
int
main(int argc, char *argv[])
{
    cmd_ln_parse(defn, argc, argv, TRUE);

    /* Run a control file if requested. */
    if (cmd_ln_str("-c")) {
        if (run_control_file(cmd_ln_str("-c")) < 0)
            return 1;
    }
    else {
        if (extract_pitch(cmd_ln_str("-i"), cmd_ln_str("-o")) < 0)
            return 1;
    }

    cmd_ln_free();
    return 0;
}
Beispiel #11
0
int
parse_cmd_ln(int argc, char *argv[])
{
  uint32      isHelp;
  uint32      isExample;

#include "cmd_ln_defn.h"

    cmd_ln_define(defn);

    if (argc == 1) {
	cmd_ln_print_definitions();
	exit(1);
    }

    cmd_ln_parse(argc, argv);

    isHelp    = *(uint32 *) cmd_ln_access("-help");
    isExample    = *(uint32 *) cmd_ln_access("-example");


    if(isHelp){
      printf("%s\n\n",helpstr);
    }

    if(isExample){
      printf("%s\n\n",examplestr);
    }

    if(isHelp || isExample){
      E_INFO("User asked for help or example.\n");
      exit(1);
    }

    if(!isHelp && !isExample){
      if (cmd_ln_validate() == FALSE) {
        E_FATAL("Unable to validate command line arguments\n");
      }

      cmd_ln_print_configuration();
    }

    return 0;
}
Beispiel #12
0
main (int32 argc, char *argv[])
{
    char *reffile, *mdeffile, *dictfile, *fdictfile;
    
    if (argc == 1) {
	cmd_ln_print_help (stderr, arglist);
	exit(0);
    }
    
    cmd_ln_parse (arglist, argc, argv);
    
    if ((mdeffile = (char *) cmd_ln_access ("-mdef")) == NULL)
	E_FATAL("-mdef argument missing\n");
    if ((dictfile = (char *) cmd_ln_access ("-dict")) == NULL)
	E_FATAL("-dict argument missing\n");
    if ((fdictfile = (char *) cmd_ln_access ("-fdict")) == NULL)
	E_FATAL("-fdict argument missing\n");
    if ((reffile = (char *) cmd_ln_access ("-ref")) == NULL)
	E_FATAL("-ref argument missing\n");

    unlimit();
    
    mdef = mdef_init (mdeffile);
    if (mdef->n_ciphone <= 0)
	E_FATAL("0 CIphones in %s\n", mdeffile);
    
    dict = dict_init (mdef, dictfile, fdictfile);
    
    process_reffile (reffile);
    
#if (0 && (! WIN32))
    fflush (stdout);
    fflush (stderr);
    system ("ps aguxwww | grep dpalign");
#endif

    exit(0);
}
Beispiel #13
0
int
parse_cmd_ln(int argc, char *argv[])
{
  uint32      isHelp;
  uint32      isExample;

    const char helpstr[] =  
"Description:\n\
\n\
Given a set of questions. Build decision tree for a set of feature of\n\
a particular phone.  By default, decision tree are not built for \n\
filler phones and the phone tagged with SIL.  One very confusing \n\
parameters of this tool is -stwt, if you are training a n-state \n\
HMM, you need to specify n values after this flag.  ";

    const char examplestr[] =
" bld_tree -treefn tree -moddeffn mdef -mixwfn mixw -meanfn mean -varfn \n\
var -psetfn questions -stwt 1.0 0.05 0.01 -state 0 -ssplitmin 1 \n\
-ssplitmax 7 -ssplitthr 1e-10 -csplitmin 1 -csplitmax 2000 -csplitthr \n\
1e-10 -cntthresh 10";

    static arg_t defn[] = {
	{ "-help",
	  ARG_BOOLEAN,
	  "no",
	  "Shows the usage of the tool"},

	{ "-example",
	  ARG_BOOLEAN,
	  "no",
	  "Shows example of how to use the tool"},

	{ "-treefn",
	  ARG_STRING,
	  NULL,
	  "Name of output tree file to produce" },

	{ "-moddeffn",
	  ARG_STRING,
	  NULL,
	  "Model definition file of the discrete models" },

        { "-ts2cbfn",
          ARG_STRING,
          ".semi.",
          "The type of models to build trees on" },

	{ "-meanfn",
	  ARG_STRING,
	  NULL,
	  "means file for tree building using continuous HMMs" },

	{ "-varfn",
	  ARG_STRING,
	  NULL,
	  "variances file for tree building using continuous HMMs" },

	{ "-fullvar",
	  ARG_BOOLEAN,
	  "no",
	  "variances file contains full covariances" },

        { "-varfloor",
          ARG_FLOAT32,
          "0.00001",
          "The minimum variance"},

        { "-cntthresh",
          ARG_FLOAT32,
          "0.00001",
          "Ignore all states with counts less than this"},

	{ "-mixwfn",
	  ARG_STRING,
	  NULL,
	  "PDF's for tree building using semicontinuous HMMs" },

	{ "-psetfn",
	  ARG_STRING,
	  NULL,
	  "phone set definitions for phonetic questions" },

	{ "-phone",
	  ARG_STRING,
	  NULL,
	  "Build trees over n-phones having this base phone"},

	{ "-allphones",
	  ARG_BOOLEAN,
	  "no",
	  "Build trees over all n-phones"},

	{ "-state",
	  ARG_INT32,
	  NULL,
	  "Build tree for this state position. E.g. For a three state HMM, this value can be 0,1 or 2. For a 5 state HMM, this value can be 0,1,2,3 or 4, and so on "},

	{ "-mwfloor",
	  ARG_FLOAT32,
	  "1e-4",
	  "Mixing weight floor for tree building"},

	{ "-stwt",
	  ARG_STRING_LIST,
	  NULL,
	  "Weights on neighboring states, This flag needs a string of numbers equal to the number of HMM-states"},

	{ "-ssplitthr",
	  ARG_FLOAT32,
	  "8e-4",
	  "Simple node splitting threshold" },

	{ "-ssplitmin",
	  ARG_INT32,
	  "1",
	  "Minimum of simple tree splits to do."},

	{ "-ssplitmax",
	  ARG_INT32,
	  "5",
	  "The maximum number of bifurcations in the simple tree before it is used to build complex questions."},

	{ "-csplitthr",
	  ARG_FLOAT32,
	  "8e-4",
	  "Compound node splitting threshold" },

	{ "-csplitmin",
	  ARG_INT32,
	  "1",
	  "Minimum # of compound tree splits to do" },

	{ "-csplitmax",
	  ARG_INT32,
	  "100",
	  "Minimum # of compound tree splits to do" },

	{NULL, 0, NULL, NULL}
    };

    cmd_ln_parse(defn, argc, argv, 1);

    isHelp    = cmd_ln_int32("-help");
    isExample    = cmd_ln_int32("-example");

    if(isHelp){
      printf("%s\n\n",helpstr);
    }

    if(isExample){
      printf("%s\n\n",examplestr);
    }

    if(isHelp || isExample){
      E_INFO("User asked for help or example.\n");
      exit(0);
    }

    return 0;
}
Beispiel #14
0
int32 parse_cmd_ln(int argc, char *argv[])
{
  uint32      isHelp;
  uint32      isExample;

  const char helpstr[]=
"Description: \n\
Convert s3 model definition file and s3 mixture weight file to a s2 senddump file.";

  const char examplestr[]=
"Example: \n\
\n\
mk_s2sendump -moddeffn s3mdef -mixwfn s3mixw -sendumpfn s2dir/sendump\n";

    static arg_def_t defn[] = {
	{ "-help",
	  CMD_LN_BOOLEAN,
	  CMD_LN_NO_VALIDATION,
	  "no",
	  "Shows the usage of the tool"},

	{ "-example",
	  CMD_LN_BOOLEAN,
	  CMD_LN_NO_VALIDATION,
	  "no",
	  "Shows example of how to use the tool"},

	{ "-moddeffn",
	      CMD_LN_STRING,
	      CMD_LN_NO_VALIDATION,
	      CMD_LN_NO_DEFAULT,
	      "The model definition file for the model inventory to train" },
	{ "-mixwfn",
	      CMD_LN_STRING,
	      CMD_LN_NO_VALIDATION,
	      CMD_LN_NO_DEFAULT,
	      "The mixture weight parameter file name"},
	{ "-sendumpfn",
	      CMD_LN_STRING,
	      CMD_LN_NO_VALIDATION,
	      CMD_LN_NO_DEFAULT,
	      "Output sendump file name"},
	{ "-pocketsphinx",
	  CMD_LN_BOOLEAN,
	  CMD_LN_NO_VALIDATION,
	  "no",
	  "Write a PocketSphinx-format senone dump file"},
	{ "-mwfloor",
	  CMD_LN_FLOAT32,
	  CMD_LN_NO_VALIDATION,
	  "0.00001",
	  "Mixing weight smoothing floor" },

	{ NULL,
	      CMD_LN_UNDEF,
	      CMD_LN_NO_VALIDATION,
	      CMD_LN_NO_DEFAULT,
	      NULL }
    };

    cmd_ln_define(defn);

    if (argc == 1) {
	cmd_ln_print_definitions();
	exit(1);
    }

    cmd_ln_parse(argc, argv);

    isHelp    = *(uint32 *) cmd_ln_access("-help");
    isExample    = *(uint32 *) cmd_ln_access("-example");


    if(isHelp){
      printf("%s\n\n",helpstr);
    }

    if(isExample){
      printf("%s\n\n",examplestr);
    }

    if(isHelp || isExample){
      E_INFO("User asked for help or example.\n");
      exit(1);
    }
    if(!isHelp && !isExample){
      cmd_ln_print_configuration();
    }

    return 0;
}
Beispiel #15
0
int
parse_cmd_ln(int argc, char *argv[])
{
    uint32      isHelp;
    uint32      isExample;

    const char helpstr[] =
        "Description: \n\
(copied from Eric's comments)\n\
 * 	Create a tied-state-to-codebook mapping file for semi-continuous, \n\
 *	phone dependent or fully continuous Gaussian density tying.";

    const char examplestr[]=
        "Example: \n\
(By Arthur: Not sure, may be obsolete) \n\
mk_ts2cb -moddeffn semi -ts2cbfn ts2cb";

    static arg_t defn[] = {
        {   "-help",
            ARG_BOOLEAN,
            "no",
            "Shows the usage of the tool"
        },

        {   "-example",
            ARG_BOOLEAN,
            "no",
            "Shows example of how to use the tool"
        },

        {   "-ts2cbfn",
            ARG_STRING,
            NULL,
            "A SPHINX-III tied-state-to-cb file name"
        },
        {   "-moddeffn",
            ARG_STRING,
            NULL,
            "A SPHINX-III model definition file name"
        },
        {   "-tyingtype",			/* either "semi", "pd", or "cont" */
            ARG_STRING,
            "semi",
            "Output a state parameter def file for fully continuous models"
        },
        {   "-pclassfn",			/* this switch is reference for -tyingtype pd */
            ARG_STRING,
            NULL,
            "A SPHINX-II phone class file name"
        },
        {   NULL,
            0,
            NULL,
            NULL
        }
    };

    cmd_ln_parse(defn, argc, argv, TRUE);

    isHelp    = cmd_ln_int32("-help");
    isExample    = cmd_ln_int32("-example");

    if(isHelp) {
        printf("%s\n\n",helpstr);
    }

    if(isExample) {
        printf("%s\n\n",examplestr);
    }

    if(isHelp || isExample) {
        E_INFO("User asked for help or example.\n");
        exit(0);
    }


    return 0;
}
Beispiel #16
0
int
parse_cmd_ln(int argc, char *argv[])
{
  uint32      isHelp;
  uint32      isExample;

  const char helpstr[]=
"Description : \n\
  Create a model definition file with tied state from model definition file without tied states. ";

  const char examplestr[]=
"Example: \n\
  tiestate -imoddeffn imdef -omoddeffn omdef -treedir trees -psetfn questions \n\
\n\
  This is an example of the input and output format, Find more details at, \n\
  http://www.speech.cs.cmu.edu/sphinxman";

    static arg_def_t defn[] = {
	{ "-help",
	  CMD_LN_BOOLEAN,
	  CMD_LN_NO_VALIDATION,
	  "no",
	  "Shows the usage of the tool"},

	{ "-example",
	  CMD_LN_BOOLEAN,
	  CMD_LN_NO_VALIDATION,
	  "no",
	  "Shows example of how to use the tool"},

	{ "-imoddeffn",
	  CMD_LN_STRING,
	  CMD_LN_NO_VALIDATION,
	  CMD_LN_NO_DEFAULT,
	  "Untied-state model definition file"},

	{ "-omoddeffn",
	  CMD_LN_STRING,
	  CMD_LN_NO_VALIDATION,
	  CMD_LN_NO_DEFAULT,
	  "Tied-state model definition file"},

	{ "-treedir",
	  CMD_LN_STRING,
	  CMD_LN_NO_VALIDATION,
	  CMD_LN_NO_DEFAULT,
	  "SPHINX-III tree directory containing pruned trees"},

	{ "-psetfn",
	  CMD_LN_STRING,
	  CMD_LN_NO_VALIDATION,
	  CMD_LN_NO_DEFAULT,
	  "Phone set definiton file" },

	{ "-allphones",
	  CMD_LN_BOOLEAN,
	  CMD_LN_NO_VALIDATION,
	  "no",
	  "Use a single tree for each state of all phones"},
	  
	{ NULL, CMD_LN_UNDEF, CMD_LN_NO_VALIDATION, CMD_LN_NO_DEFAULT, NULL }
    };

    cmd_ln_define(defn);

    if (argc == 1) {
	cmd_ln_print_definitions();
	exit(1);
    }

    cmd_ln_parse(argc, argv);

    if (cmd_ln_validate() == FALSE) {
	E_FATAL("Unable to validate command line arguments\n");
    }

    isHelp    = *(uint32 *) cmd_ln_access("-help");
    isExample    = *(uint32 *) cmd_ln_access("-example");


    if(isHelp){
      printf("%s\n\n",helpstr);
    }

    if(isExample){
      printf("%s\n\n",examplestr);
    }

    if(isHelp || isExample){
      E_INFO("User asked for help or example.\n");
      exit(1);
    }
    if(!isHelp && !isExample){
      cmd_ln_print_configuration();
    }

    return 0;
}
Beispiel #17
0
int32 main (int32 argc, char *argv[])
{
    FILE *fpout;
    mgau_model_t *mgau;
    int32 **subvec;
    int32 max_datarows, datarows, datacols, svqrows, svqcols;
    float32 **data, **vqmean;
    int32 *datamap, *vqmap;
    float64 sqerr;
    int32 stdev;
    int32 i, j, v, m, c;
    
    cmd_ln_parse (arg, argc, argv);
    
    logs3_init ((float64) 1.0003);
    
    /* Load means/vars but DO NOT precompute variance inverses or determinants */
    mgau = mgau_init (cmd_ln_str("-mean"), cmd_ln_str("-var"), 0.0 /* no varfloor */,
		      cmd_ln_str("-mixw"), cmd_ln_float64 ("-mixwfloor"),
		      FALSE);
    mgau_var_nzvec_floor (mgau, cmd_ln_float64 ("-varfloor"));
    
    /* Parse subvector spec argument; subvec is null terminated; subvec[x] is -1 terminated */
    subvec = parse_subvecs (cmd_ln_str("-svspec"));
    
    if (cmd_ln_str ("-subvq"))
	fpout = myfopen (cmd_ln_str ("-subvq"), "w");
    else
	fpout = stdout;
    
    /* Echo command line to output file */
    for (i = 0; i < argc-1; i++)
	fprintf (fpout, "# %s \\\n", argv[i]);
    fprintf (fpout, "# %s\n#\n", argv[argc-1]);
    
    /* Print input and output configurations to output file */
    for (v = 0; subvec[v]; v++);		/* No. of subvectors */
    svqrows = cmd_ln_int32 ("-svqrows");
    fprintf (fpout, "VQParam %d %d -> %d %d\n",
	     mgau_n_mgau(mgau), mgau_max_comp(mgau), v, svqrows);
    for (v = 0; subvec[v]; v++) {
	for (i = 0; subvec[v][i] >= 0; i++);
	fprintf (fpout, "Subvector %d length %d ", v, i);
	for (i = 0; subvec[v][i] >= 0; i++)
	    fprintf (fpout, " %2d", subvec[v][i]);
	fprintf (fpout, "\n");
    }
    fflush (fpout);
    
    /*
     * datamap[] for identifying non-0 input vectors that take part in the clustering process:
     *     datamap[m*max_mean + c] = row index of data[][] containing the copy.
     * vqmap[] for mapping vq input data to vq output.
     */
    max_datarows = mgau_n_mgau(mgau) * mgau_max_comp(mgau);
    datamap = (int32 *) ckd_calloc (max_datarows, sizeof(int32));
    vqmap = (int32 *) ckd_calloc (max_datarows, sizeof(int32));
    
    stdev = cmd_ln_int32 ("-stdev");
    
    /* Copy and cluster each subvector */
    for (v = 0; subvec[v]; v++) {
	E_INFO("Clustering subvector %d\n", v);
	
	for (datacols = 0; subvec[v][datacols] >= 0; datacols++);	/* Input subvec length */
	svqcols = datacols * 2;		/* subvec length after concatenating mean + var */
	
	/* Allocate input/output data areas */
	data = (float32 **) ckd_calloc_2d (max_datarows, svqcols, sizeof(float32));
	vqmean = (float32 **) ckd_calloc_2d (svqrows, svqcols, sizeof(float32));
	
	/* Make a copy of the subvectors from the input data, and initialize maps */
	for (i = 0; i < max_datarows; i++)
	    datamap[i] = -1;
	datarows = 0;
	for (m = 0; m < mgau_n_mgau(mgau); m++) {		/* For each mixture m */
	    for (c = 0; c < mgau_n_comp(mgau, m); c++) {	/* For each component c in m */
		if (vector_is_zero (mgau_var(mgau, m, c), mgau_veclen(mgau)))
		    continue;
		
		for (i = 0; i < datacols; i++) {	/* Copy specified dimensions, mean+var */
		    data[datarows][i*2]   = mgau->mgau[m].mean[c][subvec[v][i]];
		    data[datarows][i*2+1] = (! stdev) ?
			mgau->mgau[m].var[c][subvec[v][i]] :
			sqrt(mgau->mgau[m].var[c][subvec[v][i]]);
		}
		datamap[m * mgau_max_comp(mgau) + c] = datarows++;
	    }
	}
	
	E_INFO("Sanity check: input data[0]:\n");
	vector_print (stderr, data[0], svqcols);
	
	for (i = 0; i < max_datarows; i++)
	    vqmap[i] = -1;
#if 0
	{
	    int32 **in;
	    
	    printf ("Input data: %d x %d\n", datarows, svqcols);
	    in = (int32 **)data;
	    for (i = 0; i < datarows; i++) {
		printf ("%8d:", i);
		for (j = 0; j < svqcols; j++)
		    printf (" %08x", in[i][j]);
		printf ("\n");
	    }
	    for (i = 0; i < datarows; i++) {
		printf ("%15d:", i);
		for (j = 0; j < svqcols; j++)
		    printf (" %15.7e", data[i][j]);
		printf ("\n");
	    }
	    fflush (stdout);
	}
#endif
	/* VQ the subvector copy built above */
	sqerr = vector_vqgen (data, datarows, svqcols, svqrows,
			      cmd_ln_float64("-eps"), cmd_ln_int32("-iter"),
			      vqmean, vqmap);
	
	/* Output VQ */
	fprintf (fpout, "Codebook %d Sqerr %e\n", v, sqerr);
	for (i = 0; i < svqrows; i++) {
	    if (stdev) {
		/* Convert clustered stdev back to var */
		for (j = 1; j < svqcols; j += 2)
		    vqmean[i][j] *= vqmean[i][j];
	    }
	    vector_print (fpout, vqmean[i], svqcols);
	}
	
	fprintf (fpout, "Map %d\n", v);
	for (i = 0; i < max_datarows; i += mgau_max_comp(mgau)) {
	    for (j = 0; j < mgau_max_comp(mgau); j++) {
		if (datamap[i+j] < 0)
		    fprintf (fpout, " -1");
		else
		    fprintf (fpout, " %d", vqmap[datamap[i+j]]);
	    }
	    fprintf (fpout, "\n");
	}
	fflush (fpout);
	
	/* Cleanup */
	ckd_free_2d ((void **) data);
	ckd_free_2d ((void **) vqmean);
    }
    
    fprintf (fpout, "End\n");
    fclose (fpout);
    
    exit(0);
}
Beispiel #18
0
int
parse_cmd_ln(int argc, char *argv[])
{
  uint32      isHelp;
  uint32      isExample;

    const char helpstr[] =  
      "Description: \nThis program computes a mixture gaussian distribution for a set of \nspeech cepstral files for use with CDCN. The first mode is computed on only\nthe silence portions of the speech to comply with the requirements of the \nalgorithm.";

    const char examplestr[]=
"Example: \n\
\n\
cdcn_stats -cepext mfc \n\
        -ctlfn stuff.ctl \n\
        -outfn output.cdcn.dist \n\
        -nmodes 32 \n\
        -noisewidth 1.5 \n\
        -tmpfn CDCN.tmp \n\
        -ceplen 13 \n\
        -stride 10 ";

    static arg_t defn[] = {
	{ "-help",
	  ARG_BOOLEAN,
	  "no",
	  "Shows the usage of the tool"},

	{ "-example",
	  ARG_BOOLEAN,
	  "no",
	  "Shows example of how to use the tool"},

	{ "-ctlfn",
	  ARG_STRING,
	  NULL,
	  "The control file name (enumerates utts in corpus)" },
	{ "-outfn",
	  ARG_STRING,
	  NULL,
	  "The output distribution file name" },
	{ "-cepdir",
	  ARG_STRING,
	  NULL,
	  "Root directory of the cepstrum files"},
	{ "-cepext",
	  ARG_STRING,
	  "mfc",
	  "Extension of the cepstrum files"},

	{ "-maxframes",
	  ARG_INT32,
	  "-1",
	  "Maximum number of frames to read (or -1 for unlimited)"},

	{ "-cbfn",
	  ARG_STRING,
	  NULL,
	  "A previous codebook to restart EM training from" },

	{ "-nmodes",
	  ARG_INT32,
	  "32",
	  "# of Gaussians to train"},
	{ "-noisewidth",
	  ARG_FLOAT32,
	  "1.5",
	  "Width of noise band"},
	{ "-ceplen",
	  ARG_INT32,
	  "13",
	  "# of coefficients per cepstrum frame"},
	{ "-stride",
	  ARG_INT32,
	  "1",
	  "Take every -stride'th frame when computing distribution" },

	{ "-vqiter",
	  ARG_INT32,
	  "5",
	  "Max # of interations of VQ to get initial codebook"},
	{ "-vqthresh",
	  ARG_FLOAT32,
	  "1e-6",
	  "Convergence ratio for VQ"},
	{ "-emiter",
	  ARG_INT32,
	  "10",
	  "# of interations of EM to estimate distributions"},
	{ "-emthresh",
	  ARG_FLOAT32,
	  "1e-6",
	  "Convergence ratio for EM"},

	{ "-tmpfn",
	  ARG_STRING,
	  "CDCN.DIST.TEMP",
	  "The temporary file name" },

	{NULL, 0, NULL, NULL}
    };

    cmd_ln_parse(defn, argc, argv, TRUE);

    isHelp    = cmd_ln_int32("-help");
    isExample    = cmd_ln_int32("-example");

    if(isHelp){
      printf("%s\n\n",helpstr);
    }

    if(isExample){
      printf("%s\n\n",examplestr);
    }

    if(isHelp || isExample){
      E_INFO("User asked for help or example.\n");
      exit(0);
    }


    return 0;
}
int
parse_cmd_ln(int argc, char *argv[])
{
  uint32      isHelp;
  uint32      isExample;

    const char helpstr[] =  
"Description: (copied from Rita's web page.) \n\
\n\
Deleted interpolation is the final step in creating semi-continuous \n\
models. The output of deleted interpolation are semi-continuous models \n\
in sphinx-3 format. These have to be further converted to sphinx-2 \n\
format, if you want to use the SPHINX-II decoder. \n\
\n\
Deleted interpolation is an iterative process to interpolate between \n\
CD and CI mixture-weights to reduce the effects of overfitting. The \n\
data are divided into two sets, and the data from one set are used to \n\
estimate the optimal interpolation factor between CI and CD models \n\
trained from the other set. Then the two data sets are switched and \n\
this procedure is repeated using the last estimated interpolation \n\
factor as an initialization for the current step. The switching is \n\
continued until the interpolation factor converges.\n\
\n\
To do this, we need *two* balanced data sets. Instead of the actual\n\
data, however, we use the Bauim-Welch buffers, since the related math\n\
is convenient. we therefore need an *even* number of buffers that can\n\
be grouped into two sets. DI cannot be performed if you train using\n\
only one buffer. At least in the final iteration of the training, you\n\
must perform the training in (at least) two parts. You could also do\n\
this serially as one final iteration of training AFTER BW has\n\
converged, on a non-lsf setup.\n\
\n\
Note here that the norm executable used at the end of every Baum-Welch \n\
iteration also computes models from the buffers, but it does not\n\
require an even number of buffers. BW returns numerator terms and\n\
denominator terms for the final estimation, and norm performs the\n\
actual division. The number of buffers is not important, but you would \n\
need to run norm at the end of EVERY iteration of BW, even if you did\n\
the training in only one part. When you have multiple parts norm sums\n\
up the numerator terms from the various buffers, and the denominator\n\
terms, and then does the division. ";

    const char examplestr[]=
"delint -accumdirs accumdir -moddeffn mdef -mixwfn mixw -cilambda 0.9 -maxiter 4000";

    static arg_t defn[] = {
	{ "-help",
	  ARG_BOOLEAN,
	  "no",
	  "Shows the usage of the tool"},

	{ "-example",
	  ARG_BOOLEAN,
	  "no",
	  "Shows example of how to use the tool"},

	{ "-moddeffn",
	  ARG_STRING,
	  NULL,
	  "The model definition file name"},
	{ "-mixwfn",
	  ARG_STRING,
	  NULL,
	  "The mixture weight parameter file name"},
	{ "-accumdirs",
	  ARG_STRING_LIST,
	  NULL,
	  "A path where accumulated counts are to be read." },
	{ "-cilambda",
	  ARG_FLOAT32,
	  "0.9",
	  "Weight of CI distributions with respect to uniform distribution"},
	{ "-maxiter",
	  ARG_INT32,
	  "100",
	  "max # of iterations if no lambda convergence"},

	{NULL, 0, NULL, NULL}
    };

    cmd_ln_parse(defn, argc, argv, 1);


    isHelp    = cmd_ln_int32("-help");
    isExample    = cmd_ln_int32("-example");

    if(isHelp){
      printf("%s\n\n",helpstr);
    }

    if(isExample){
      printf("%s\n\n",examplestr);
    }

    if(isHelp || isExample){
      E_INFO("User asked for help or example.\n");
      exit(0);
    }

    return 0;
}
int
parse_cmd_ln(int argc, char *argv[])
{
  uint32      isHelp;
  uint32      isExample;

  const char helpstr[]=
"Description: \n"
"Create the senone to mllr class mapping. This program just reads the mapping from \n"
"stdin one map per line and converts it to binary form. No real work on estimation \n"
"of the number of classes id done. The format of the input maps is simple, \n"
"just one mapping per line:\n"
"\n"
"0\n"
"0\n"
"0\n"
"1\n"
"\n"
"Which means that we map senones 0,1,2 to class 0 and senone 3 to class 1.";

  const char examplestr[]=
"Example: \n\
mk_mllr_class -nmap 100 -nclass 4 -cb2mllrfn out.cb2mllr.bin < in.cb2mllr.txt";

    static arg_t defn[] = {
	{ "-help",
	  ARG_BOOLEAN,
	  "no",
	  "Shows the usage of the tool"},

	{ "-example",
	  ARG_BOOLEAN,
	  "no",
	  "Shows example of how to use the tool"},

	{ "-nmap",
	  ARG_INT32,
	  NULL,
	  "# of codebook -> MLLR class mappings" },

	{ "-nclass",
	  ARG_INT32,
	  NULL,
	  "# of MLLR classes to map into" },

	{ "-cb2mllrfn",
	  ARG_STRING,
	  NULL,
	  "Codebook-to-MLLR mapping file to create" },

	{NULL, 0, NULL, NULL}
	  
    };

    cmd_ln_parse(defn, argc, argv, TRUE);

    isHelp    = cmd_ln_int32("-help");
    isExample    = cmd_ln_int32("-example");

    if(isHelp){
      printf("%s\n\n",helpstr);
    }

    if(isExample){
      printf("%s\n\n",examplestr);
    }

    if(isHelp || isExample){
      E_INFO("User asked for help or example.\n");
      exit(0);
    }


    return 0;
}
Beispiel #21
0
main (int32 argc, char *argv[])
{
    kb_t kb;
    kbcore_t *kbcore;
    bitvec_t active;
    int32 w;
    
    cmd_ln_parse (arglist, argc, argv);
    unlimit();
    
    kbcore = kbcore_init (cmd_ln_float32("-logbase"),
			  cmd_ln_str("-feat"),
			  cmd_ln_str("-mdef"),
			  cmd_ln_str("-dict"),
			  cmd_ln_str("-fdict"),
			  cmd_ln_str("-compsep"),
			  cmd_ln_str("-lm"),
			  cmd_ln_str("-fillpen"),
			  cmd_ln_float32("-silprob"),
			  cmd_ln_float32("-fillprob"),
			  cmd_ln_float32("-lw"),
			  cmd_ln_float32("-wip"),
			  cmd_ln_str("-mean"),
			  cmd_ln_str("-var"),
			  cmd_ln_float32("-varfloor"),
			  cmd_ln_str("-senmgau"),
			  cmd_ln_str("-mixw"),
			  cmd_ln_float32("-mixwfloor"),
			  cmd_ln_str("-tmat"),
			  cmd_ln_float32("-tmatfloor"));
    
    /* Here's the perfect candidate for inheritance */
    kb.mdef = kbcore->mdef;
    kb.dict = kbcore->dict;
    kb.lm = kbcore->lm;
    kb.fillpen = kbcore->fillpen;
    kb.tmat = kbcore->tmat;
    kb.dict2lmwid = kbcore->dict2lmwid;
    
    if ((kb.am = acoustic_init (kbcore->fcb, kbcore->gau, kbcore->sen, cmd_ln_float32("-mgaubeam"),
				S3_MAX_FRAMES)) == NULL) {
	E_FATAL("Acoustic models initialization failed\n");
    }
    kb.beam = logs3 (cmd_ln_float64("-beam"));
    kb.wordbeam = logs3 (cmd_ln_float64("-wordbeam"));
    kb.wordmax = cmd_ln_int32("-wordmax");
    
    /* Mark the active words and build lextree */
    active = bitvec_alloc (dict_size (kb.dict));
    bitvec_clear_all (active, dict_size(kb.dict));
    for (w = 0; w < dict_size(kb.dict); w++) {
	if (IS_LMWID(kb.dict2lmwid[w]) || dict_filler_word (kb.dict, w))
	    bitvec_set (active, w);
    }
    kb.lextree_root = lextree_build (kb.dict, kb.mdef, active, cmd_ln_int32("-flatdepth"));
    
    kb.vithist = (glist_t *) ckd_calloc (S3_MAX_FRAMES+2, sizeof(glist_t));
    kb.vithist++;	/* Allow for dummy frame -1 for start word */
    kb.lextree_active = NULL;
    kb.wd_last_sf = (int32 *) ckd_calloc (dict_size(kb.dict), sizeof(int32));
    
    kb.tm = (ptmr_t *) ckd_calloc (1, sizeof(ptmr_t));
    kb.tm_search = (ptmr_t *) ckd_calloc (1, sizeof(ptmr_t));
    
    ctl_process (cmd_ln_str("-ctl"), cmd_ln_int32("-ctloffset"), cmd_ln_int32("-ctlcount"),
		 decode_utt, &kb);
    
    exit(0);
}