static int acmod_init_am(acmod_t *acmod) { char const *mdeffn, *tmatfn; /* Read model definition. */ if ((mdeffn = cmd_ln_str_r(acmod->config, "-mdef")) == NULL) { E_ERROR("Must specify -mdef or -hmm\n"); return -1; } if ((acmod->mdef = bin_mdef_read(acmod->config, mdeffn)) == NULL) { E_ERROR("Failed to read model definition from %s\n", mdeffn); return -1; } /* Read transition matrices. */ if ((tmatfn = cmd_ln_str_r(acmod->config, "-tmat")) == NULL) { E_ERROR("No tmat file specified\n"); return -1; } acmod->tmat = tmat_init(tmatfn, acmod->lmath, cmd_ln_float32_r(acmod->config, "-tmatfloor"), TRUE); /* Read the acoustic models. */ if ((cmd_ln_str_r(acmod->config, "-mean") == NULL) || (cmd_ln_str_r(acmod->config, "-var") == NULL) || (cmd_ln_str_r(acmod->config, "-tmat") == NULL)) { E_ERROR("No mean/var/tmat files specified\n"); return -1; } if (cmd_ln_str_r(acmod->config, "-senmgau")) { E_INFO("Using general multi-stream GMM computation\n"); acmod->mgau = ms_mgau_init(acmod->config, acmod->lmath, acmod->mdef); if (acmod->mgau == NULL) return -1; } else { E_INFO("Attempting to use SCHMM computation module\n"); if ((acmod->mgau = s2_semi_mgau_init(acmod)) == NULL) { E_INFO("Attempting to use PTHMM computation module\n"); if ((acmod->mgau = ptm_mgau_init(acmod)) == NULL) { E_INFO("Falling back to general multi-stream GMM computation\n"); acmod->mgau = ms_mgau_init(acmod->config, acmod->lmath, acmod->mdef); if (acmod->mgau == NULL) return -1; } } } return 0; }
main (int32 argc, char *argv[]) { tmat_t *t; float64 flr; if (argc < 3) E_FATAL("Usage: %s tmat floor\n", argv[0]); if (sscanf (argv[2], "%lf", &flr) != 1) E_FATAL("Usage: %s tmat floor\n", argv[0]); logs3_init ((float64) 1.0001); t = tmat_init (argv[1], flr); tmat_dump (t); }
/* RAH, April 26th, 2001, opened file tmat_test.out and added tmat_free(t) call, there are no memory leaks here */ main (int32 argc, char *argv[]) { tmat_t *t; float64 flr; FILE *fp; if (argc < 3) E_FATAL("Usage: %s tmat floor\n", argv[0]); if (sscanf (argv[2], "%lf", &flr) != 1) E_FATAL("Usage: %s tmat floor\n", argv[0]); fp = fopen ("tmat_test.out","wt"); if (! fp) { fprintf (stderr,"Unable to topen tmat_test.out for writing\n"); exit (-1); } logs3_init ((float64) 1.0001); t = tmat_init (argv[1], flr); tmat_dump (t,fp); tmat_free (t); }
int main(int argc, char *argv[]) { dict_t *dict; dict2pid_t *d2p; bin_mdef_t *mdef; glextree_t *tree; hmm_context_t *ctx; logmath_t *lmath; tmat_t *tmat; int i; TEST_ASSERT(mdef = bin_mdef_read(NULL, MODELDIR "/hmm/en_US/hub4wsj_sc_8k/mdef")); TEST_ASSERT(dict = dict_init(cmd_ln_init(NULL, NULL, FALSE, "-dict", DATADIR "/turtle.dic", "-dictcase", "no", NULL), mdef)); TEST_ASSERT(d2p = dict2pid_build(mdef, dict)); lmath = logmath_init(1.0001, 0, TRUE); tmat = tmat_init(MODELDIR "/hmm/en_US/hub4wsj_sc_8k/transition_matrices", lmath, 1e-5, TRUE); ctx = hmm_context_init(bin_mdef_n_emit_state(mdef), tmat->tp, NULL, mdef->sseq); TEST_ASSERT(tree = glextree_build(ctx, dict, d2p, NULL, NULL)); /* Check that a path exists for all dictionary words. */ for (i = 0; i < dict_size(dict); ++i) TEST_ASSERT(glextree_has_word(tree, i)); dict_free(dict); dict2pid_free(d2p); bin_mdef_free(mdef); tmat_free(tmat); hmm_context_free(ctx); glextree_free(tree); return 0; }
static int acmod_init_am(acmod_t *acmod) { char const *mdeffn, *tmatfn, *mllrfn, *hmmdir; /* Read model definition. */ if ((mdeffn = cmd_ln_str_r(acmod->config, "-mdef")) == NULL) { if ((hmmdir = cmd_ln_str_r(acmod->config, "-hmm")) == NULL) E_ERROR("Acoustic model definition is not specified either " "with -mdef option or with -hmm\n"); else E_ERROR("Folder '%s' does not contain acoustic model " "definition 'mdef'\n", hmmdir); return -1; } if ((acmod->mdef = bin_mdef_read(acmod->config, mdeffn)) == NULL) { E_ERROR("Failed to read acoustic model definition from %s\n", mdeffn); return -1; } /* Read transition matrices. */ if ((tmatfn = cmd_ln_str_r(acmod->config, "-tmat")) == NULL) { E_ERROR("No tmat file specified\n"); return -1; } acmod->tmat = tmat_init(tmatfn, acmod->lmath, cmd_ln_float32_r(acmod->config, "-tmatfloor"), TRUE); /* Read the acoustic models. */ if ((cmd_ln_str_r(acmod->config, "-mean") == NULL) || (cmd_ln_str_r(acmod->config, "-var") == NULL) || (cmd_ln_str_r(acmod->config, "-tmat") == NULL)) { E_ERROR("No mean/var/tmat files specified\n"); return -1; } if (cmd_ln_str_r(acmod->config, "-senmgau")) { E_INFO("Using general multi-stream GMM computation\n"); acmod->mgau = ms_mgau_init(acmod, acmod->lmath, acmod->mdef); if (acmod->mgau == NULL) return -1; } else { E_INFO("Attempting to use PTM computation module\n"); if ((acmod->mgau = ptm_mgau_init(acmod, acmod->mdef)) == NULL) { E_INFO("Attempting to use semi-continuous computation module\n"); if ((acmod->mgau = s2_semi_mgau_init(acmod)) == NULL) { E_INFO("Falling back to general multi-stream GMM computation\n"); acmod->mgau = ms_mgau_init(acmod, acmod->lmath, acmod->mdef); if (acmod->mgau == NULL) return -1; } } } /* If there is an MLLR transform, apply it. */ if ((mllrfn = cmd_ln_str_r(acmod->config, "-mllr"))) { ps_mllr_t *mllr = ps_mllr_read(mllrfn); if (mllr == NULL) return -1; acmod_update_mllr(acmod, mllr); } return 0; }
bool IVCONV::smf_read ( FileIO *filein ) /******************************************************************************/ /* Purpose: SMF_READ reads an SMF file. Author: John Burkardt Modified: 03 July 1999 */ { short material_binding,normal_binding,texture_binding; //Prepare structure for reading "per face" UV mapping array<FaceUV> face_uv; long mesh_idx; unsigned long color_idx; unsigned long normal_idx; unsigned long uvmap_idx; long texture_idx; unsigned long material_base; unsigned long vertex_base; unsigned long face_base; int level; int vertex_correction; char *next; int width; char cnr[LINE_MAX_LEN]; char token[LINE_MAX_LEN]; char token2[LINE_MAX_LEN]; material_binding=BND_UNDEFINED; normal_binding=BND_UNDEFINED; texture_binding=BND_UNDEFINED; vertex_correction = 0; material_base = material_num; vertex_base = vertex_num; face_base = face_num; level = 0; color_idx=0; normal_idx=0; uvmap_idx=0; mesh_idx=-1; texture_idx=-1; // Read the next line of the file into INPUT. stats.text_num = 0; char input[LINE_MAX_LEN]; while ( filein->fgets(input,LINE_MAX_LEN) != NULL ) { stats.text_num++; if ( debug ) printf ( "SMF_READ: Reading line %u\n", stats.text_num ); // Advance to the first nonspace character in INPUT. for ( next = input; *next != '\0' && isspace(*next); next++ ) { } // Skip blank lines. if ( *next == '\0' ) { continue; } // Skip comment lines. if ( (*next == '#') || (*next == '$') ) { stats.comment_num++; continue; } // Extract the first word in this line. sscanf ( next, "%s%n", token, &width ); // Set NEXT to point to just after this token. next += width; // BEGIN // Reset the transformation matrix to identity. // Node numbering starts at zero again. (Really, this is level based) // (Really should define a new transformation matrix, and concatenate.) // (Also, might need to keep track of level.) if ( leqi(token,"BEGIN") ) { level++; // Update materials added in last block unsigned int material_idx; for (material_idx=material_base;material_idx<material_num;material_idx++) material[material_idx].texture=texture_idx; material_base = material_num; //Convert material mapping to "per vertex" if (material_binding==BND_PER_FACE) face_to_vertex_material(face_uv,face_base,face_num-face_base); //Convert UV mapping to "per vertex" if (texture_binding==BND_PER_FACE) face_to_vertex_uv(face_uv,face_base,face_num-face_base); // Create new mesh mesh[mesh_num]=Mesh(); mesh_idx=mesh_num; mesh_num++; // Clear the block-dependent variables vertex_base = vertex_num; face_base = face_num; color_idx=0; normal_idx=0; uvmap_idx=0; texture_idx=-1; tmat_init ( transform_matrix ); } else // BIND [c|n|r] [vertex|face] // Specify the binding for RGB color, Normal, or Texture. // Options are "vertex" or "face" if ( leqi( token, "BIND" ) ) { char type[LINE_MAX_LEN]; sscanf ( next, "%s%n", cnr, &width ); next += width; sscanf ( next, "%s%n", type, &width ); next += width; if ( debug ) printf ( "SMF_READ: Bind - CNR=%s, TYPE=%s\n",cnr,type ); if ( leqi(cnr,"C") ) { if ( leqi(type,"VERTEX") ) { material_binding=BND_PER_VERTEX; } else if ( leqi(type,"FACE") ) { material_binding=BND_PER_FACE; } else { stats.bad_num++; printf ( "SMF_READ: Unrecognized material binding in line %u (ignored).\n",stats.text_num ); } } else if ( leqi(cnr,"N") ) { if ( leqi(type,"VERTEX") ) { normal_binding=BND_PER_VERTEX; } else if ( leqi(type,"FACE") ) { normal_binding=BND_PER_FACE; } else { stats.bad_num++; printf ( "SMF_READ: Unrecognized normal binding in line %u (ignored).\n",stats.text_num ); } } else if ( leqi ( cnr, "R" ) ) { if ( leqi(type,"VERTEX") ) { texture_binding=BND_PER_VERTEX; } else if ( leqi(type,"FACE") ) { texture_binding=BND_PER_FACE; } else { stats.bad_num++; printf ( "SMF_READ: Unrecognized texture binding in line %u (ignored).\n",stats.text_num ); } } else { stats.bad_num++; printf ( "SMF_READ: Unrecognized binding in line %u (ignored).\n",stats.text_num ); } } else // C <r> <g> <b> // Specify an RGB color, with R, G, B between 0.0 and 1.0. if ( leqi(token,"C") ) { int count=1; float r,g,b; if (count==1) count = sscanf ( next, "%f%n", &r, &width ); next += width; if (count==1) count = sscanf ( next, "%f%n", &g, &width ); next += width; if (count==1) count = sscanf ( next, "%f%n", &b, &width ); next += width; if (count!=1) { stats.bad_num++; printf ( "SMF_READ: Couldn't read color in line %u (ignored).\n",stats.text_num ); continue; } // Set up a temporary material (R,G,B,1.0). // Add the material to the material database, or find the index of // a matching material already in. // Assign the material of the node or face to this index. unsigned int material_idx; material[material_num]=Material(r,g,b); material_idx = material_num; material_num++; if (material_binding==BND_PER_FACE) { // Make sure we won't initialize the FaceUV twice if (color_idx>=uvmap_idx) face_uv[color_idx]=FaceUV(); face_uv[color_idx].material=material_idx; } else if (material_binding==BND_PER_VERTEX) { if (vertex_base+color_idx < vertex_num) { vertex[vertex_base+color_idx].material=material_idx; } else { stats.bad_num++; printf ( "SMF_READ: More colors than vertices in line %u (ignored).\n",stats.text_num ); } } else { stats.bad_num++; printf ( "SMF_READ: Color error - Material binding undefined in line %u (ignored).\n",stats.text_num ); } color_idx++; } else // END // Drop down a level. if ( leqi(token,"END") ) { level--; if ( level < 0 ) { printf ( "\n" ); printf ( "SMF_READ - Fatal error!\n" ); printf ( " More END statements than BEGINs!\n" ); return false; } // Update materials added in last block unsigned int material_idx; for (material_idx=material_base;material_idx<material_num;material_idx++) material[material_idx].texture=texture_idx; material_base = material_num; //Convert material mapping to "per vertex" if (material_binding==BND_PER_FACE) face_to_vertex_material(face_uv,face_base,face_num-face_base); //Convert UV mapping to "per vertex" if (texture_binding==BND_PER_FACE) face_to_vertex_uv(face_uv,face_base,face_num-face_base); // Back to previous mesh mesh_idx--; color_idx=0; normal_idx=0; uvmap_idx=0; } else // F V1 V2 V3 // Face. // A face is defined by the vertices. // Node indices are 1 based rather than 0 based. // So we have to decrement them before loading them into FACE. // Note that vertex indices start back at 0 each time a BEGIN is entered. // The strategy here won't handle nested BEGIN's, just one at a time. if ( leqi(token,"F") ) { if (face_num>=FACES_MAX) { stats.bad_num++; if (stats.bad_num<16) printf ( "SMF_READ: Faces limit reached in line %u (ignored).\n",stats.text_num ); continue; } unsigned long face_idx; face[face_num] = Face(); face_idx=face_num; face_num++; if (mesh_idx<0) { mesh[mesh_num]=Mesh(); mesh_idx=mesh_num; mesh_num++; } face[face_num].mesh=mesh_idx; // Read each item in the F definition as a token, and then // take it apart. int ivert; for (ivert=0;ivert<ORDER_MAX;ivert++ ) { int count=1; int node; if (count==1) count = sscanf ( next, "%s%n", token2, &width ); next += width; if (count==1) count = sscanf ( token2, "%d%n", &node, &width ); if (count!=1) break; unsigned long vertex_idx=node + vertex_base - 1 + vertex_correction; if (vertex_idx<vertex_num) { face[face_idx].vertices[ivert] = vertex_idx; face[face_idx].order++; } else { printf ( "SMF_READ: Warning - face definition had nonexisting vertex.\n" ); } } if (ivert==ORDER_MAX) printf ( "SMF_READ: Warning - max order reached, face truncated in line %u.\n",stats.text_num ); else if ((debug)&&(face[face_idx].order<3)) printf ( "SMF_READ: Warning - face order smaller than 3 in line %u.\n",stats.text_num ); } else // N <x> <y> <z> // Specify a normal vector. if ( leqi ( token, "N" ) ) { int count=1; float x,y,z; if (count==1) count = sscanf ( next, "%f%n", &x, &width ); next += width; if (count==1) count = sscanf ( next, "%f%n", &y, &width ); next += width; if (count==1) count = sscanf ( next, "%f%n", &z, &width ); next += width; if (count!=1) { stats.bad_num++; printf ( "SMF_READ: Couldn't read normal vector in line %u (ignored).\n",stats.text_num ); continue; } if (normal_binding==BND_PER_FACE) { unsigned long face_idx=face_base+normal_idx; if (face_idx<face_num) { face[face_idx].normal=vec3(x,y,z); } else { stats.bad_num++; printf ( "SMF_READ: Normal vector for nonexisting face in line %u (ignored).\n",stats.text_num ); } } else if (normal_binding==BND_PER_VERTEX) { unsigned long vertex_idx=vertex_base+normal_idx; if (vertex_idx<vertex_num) { vertex[vertex_idx].normal=vec3(x,y,z); } else { stats.bad_num++; printf ( "SMF_READ: Normal vector for nonexisting vertex in line %u (ignored).\n",stats.text_num ); } } else { stats.bad_num++; if (stats.bad_num<16) printf ( "SMF_READ: Normal vector error - binding undefined in line %u (ignored).\n",stats.text_num ); } normal_idx++; } else // R <u> <v> // Specify a texture coordinate. if ( leqi(token,"R") ) { int count=1; float u,v; if (count==1) count = sscanf ( next, "%f%n", &u, &width ); next += width; if (count==1) count = sscanf ( next, "%f%n", &v, &width ); next += width; if (count!=1) { stats.bad_num++; printf ( "SMF_READ: Couldn't read UV mapping in line %u (ignored).\n",stats.text_num ); continue; } if (texture_binding==BND_PER_FACE) { // Make sure we won't initialize the FaceUV twice if (uvmap_idx>=color_idx) face_uv[uvmap_idx]=FaceUV(); face_uv[uvmap_idx].tex_uv[face_uv[uvmap_idx].order]=vec2(u,v); face_uv[uvmap_idx].order++; } else if (texture_binding==BND_PER_VERTEX) { unsigned long vertex_idx=vertex_base+uvmap_idx; if (vertex_idx<vertex_num) { vertex[vertex_idx].tex_uv=vec2(u,v); } else { stats.bad_num++; printf ( "SMF_READ: UV mapping for nonexisting vertex in line %u (ignored).\n",stats.text_num ); } } else { stats.bad_num++; if (stats.bad_num<16) printf ( "SMF_READ: UV mapping error - binding undefined in line %u (ignored).\n",stats.text_num ); } uvmap_idx++; } else // ROT [x|y|z] <theta> if ( leqi(token,"ROT") ) { int count=1; float angle; char axis; if (count==1) sscanf ( next, "%c%n", &axis, &width ); next += width; if (count==1) sscanf ( next, "%f%n", &angle, &width ); next += width; if (count!=1) { stats.bad_num++; printf ( "SMF_READ: Couldn't read rotation in line %u (ignored).\n",stats.text_num ); continue; } tmat_rot_axis ( transform_matrix, transform_matrix, angle, axis ); } else // SCALE <sx> <sy> <sz> if ( leqi(token,"SCALE") ) { int count=1; float x,y,z; if (count==1) count = sscanf ( next, "%f%n", &x, &width ); next += width; if (count==1) count = sscanf ( next, "%f%n", &y, &width ); next += width; if (count==1) count = sscanf ( next, "%f%n", &z, &width ); next += width; if (count!=1) { stats.bad_num++; printf ( "SMF_READ: Couldn't read scale in line %u (ignored).\n",stats.text_num ); continue; } tmat_scale ( transform_matrix, transform_matrix, x, y, z ); } else // SET VERTEX_CORRECTION <i> // Specify increment to add to vertex indices in file. if ( leqi(token,"SET") ) { int count=1; int vcorrct; if (count==1) count = sscanf ( next, "%s%n", cnr, &width ); next += width; if (count==1) count = sscanf ( next, "%d%n", &vcorrct, &width ); next += width; if (count!=1) { stats.bad_num++; printf ( "SMF_READ: Couldn't read vertex correction in line %u (ignored).\n",stats.text_num ); vertex_correction=0; continue; } vertex_correction=vcorrct; } else // T_SCALE <dx> <dy> // Specify a scaling to texture coordinates. if ( leqi(token,"T_SCALE") ) { int count=1; float dx,dy; if (count==1) count = sscanf ( next, "%f%n", &dx, &width ); next += width; if (count==1) count = sscanf ( next, "%f%n", &dy, &width ); next += width; if (count!=1) { stats.bad_num++; printf ( "SMF_READ: Couldn't read texture scale in line %u (ignored).\n",stats.text_num ); continue; } //TODO: store the scaling } else // T_TRANS <dx> <dy> // Specify a translation to texture coordinates. if ( leqi(token,"T_TRANS") ) { int count=1; float dx,dy; if (count==1) count = sscanf ( next, "%f%n", &dx, &width ); next += width; if (count==1) count = sscanf ( next, "%f%n", &dy, &width ); next += width; if (count!=1) { stats.bad_num++; printf ( "SMF_READ: Couldn't read texture translation in line %u (ignored).\n",stats.text_num ); continue; } //TODO: store the value } else // TEX <filename> // Specify a filename containing the texture. if ( leqi(token,"TEX") ) { int count=1; int vcorrct; if (count==1) count = sscanf ( next, "%s%n", cnr, &width ); if (count!=1) { stats.bad_num++; printf ( "SMF_READ: Couldn't read texture name in line %u (ignored).\n",stats.text_num ); continue; } texture[texture_num]=Texture(); texture_num++; texture_idx=texture_num; strncpy(texture[texture_idx].name,cnr,LINE_MAX_LEN); // TODO: set materials to this texture } else // TRANS <dx> <dy> <dz> if ( leqi(token,"TRANS") ) { int count=1; float x,y,z; if (count==1) count = sscanf ( next, "%f%n", &x, &width ); next += width; if (count==1) count = sscanf ( next, "%f%n", &y, &width ); next += width; if (count==1) count = sscanf ( next, "%f%n", &z, &width ); next += width; if (count!=1) { stats.bad_num++; printf ( "SMF_READ: Couldn't read transform vector in line %u (ignored).\n",stats.text_num ); continue; } tmat_trans ( transform_matrix, transform_matrix, x, y, z ); } else // V <X> <Y> <Z> // Geometric vertex. if ( leqi(token,"V") ) { if (vertex_num>=VERTICES_MAX) { stats.bad_num++; if (stats.bad_num<10) printf ( "SMF_READ: Vertex limit reached in line %u (ignored).\n",stats.text_num ); continue; } int count; float xvec[3]; count = sscanf ( next, "%e %e %e",&(xvec[0]),&(xvec[1]),&(xvec[2])); if (count!=3) { stats.bad_num++; printf ( "SMF_READ: Couldn't read vertex coords in line %u (ignored).\n",stats.text_num ); continue; } vertex[vertex_num]=Vertex(); vertex[vertex_num].cor3=vec3(xvec[0],xvec[1],xvec[2]); // Apply current transformation matrix. // Right now, we can only handle one matrix, not a stack of // matrices representing nested BEGIN/END's. tmat_mxp ( transform_matrix, xvec, xvec ); vertex_num++; } else // Unrecognized keyword. { stats.bad_num++; if ( stats.bad_num <= 10 ) { printf ( "SMF_READ: Bad data in line %u (ignored).\n", stats.text_num ); } } } // Update materials added in last block unsigned int material_idx; for (material_idx=material_base;material_idx<material_num;material_idx++) material[material_idx].texture=texture_idx; //Convert material mapping to "per vertex" if (material_binding==BND_PER_FACE) face_to_vertex_material(face_uv,face_base,face_num-face_base); //Convert UV mapping to "per vertex" if (texture_binding==BND_PER_FACE) face_to_vertex_uv(face_uv,face_base,face_num-face_base); if ( debug ) printf ( "SMF_READ: Finished analyzing file lines.\n" ); return true; }
/* * Load and cross-check all models (acoustic/lexical/linguistic). */ static void models_init ( void ) { float32 varfloor, mixwfloor, tpfloor; int32 i, s; s3cipid_t ci; s3wid_t w; char *arg; dict_t *dict; /* HMM model definition */ mdef = mdef_init ((char *) cmd_ln_access("-mdeffn")); /* Dictionary */ dict = dict_init ((char *) cmd_ln_access("-dictfn"), (char *) cmd_ln_access("-fdictfn")); /* HACK!! Make sure SILENCE_WORD, START_WORD and FINISH_WORD are in dictionary */ silwid = dict_wordid (SILENCE_WORD); startwid = dict_wordid (START_WORD); finishwid = dict_wordid (FINISH_WORD); if (NOT_WID(silwid) || NOT_WID(startwid) || NOT_WID(finishwid)) { E_FATAL("%s, %s, or %s missing from dictionary\n", SILENCE_WORD, START_WORD, FINISH_WORD); } if ((dict->filler_start > dict->filler_end) || (! dict_filler_word (silwid))) E_FATAL("%s must occur (only) in filler dictionary\n", SILENCE_WORD); /* No check that alternative pronunciations for filler words are in filler range!! */ /* Codebooks */ varfloor = *((float32 *) cmd_ln_access("-varfloor")); g = gauden_init ((char *) cmd_ln_access("-meanfn"), (char *) cmd_ln_access("-varfn"), varfloor); /* Verify codebook feature dimensions against libfeat */ n_feat = feat_featsize (&featlen); if (n_feat != g->n_feat) E_FATAL("#feature mismatch: s2= %d, mean/var= %d\n", n_feat, g->n_feat); for (i = 0; i < n_feat; i++) if (featlen[i] != g->featlen[i]) E_FATAL("featlen[%d] mismatch: s2= %d, mean/var= %d\n", i, featlen[i], g->featlen[i]); /* Senone mixture weights */ mixwfloor = *((float32 *) cmd_ln_access("-mwfloor")); sen = senone_init ((char *) cmd_ln_access("-mixwfn"), (char *) cmd_ln_access("-senmgaufn"), mixwfloor); /* Verify senone parameters against gauden parameters */ if (sen->n_feat != g->n_feat) E_FATAL("#Feature mismatch: gauden= %d, senone= %d\n", g->n_feat, sen->n_feat); if (sen->n_cw != g->n_density) E_FATAL("#Densities mismatch: gauden= %d, senone= %d\n", g->n_density, sen->n_cw); if (sen->n_gauden > g->n_mgau) E_FATAL("Senones need more codebooks (%d) than present (%d)\n", sen->n_gauden, g->n_mgau); if (sen->n_gauden < g->n_mgau) E_ERROR("Senones use fewer codebooks (%d) than present (%d)\n", sen->n_gauden, g->n_mgau); /* Verify senone parameters against model definition parameters */ if (mdef->n_sen != sen->n_sen) E_FATAL("Model definition has %d senones; but #senone= %d\n", mdef->n_sen, sen->n_sen); /* CD/CI senone interpolation weights file, if present */ if ((arg = (char *) cmd_ln_access ("-lambdafn")) != NULL) { interp = interp_init (arg); /* Verify interpolation weights size with senones */ if (interp->n_sen != sen->n_sen) E_FATAL("Interpolation file has %d weights; but #senone= %d\n", interp->n_sen, sen->n_sen); } else interp = NULL; /* Transition matrices */ tpfloor = *((float32 *) cmd_ln_access("-tpfloor")); tmat = tmat_init ((char *) cmd_ln_access("-tmatfn"), tpfloor); /* Verify transition matrices parameters against model definition parameters */ if (mdef->n_tmat != tmat->n_tmat) E_FATAL("Model definition has %d tmat; but #tmat= %d\n", mdef->n_tmat, tmat->n_tmat); if (mdef->n_emit_state != tmat->n_state-1) E_FATAL("#Emitting states in model definition = %d, #states in tmat = %d\n", mdef->n_emit_state, tmat->n_state); arg = (char *) cmd_ln_access ("-agc"); if ((strcmp (arg, "max") != 0) && (strcmp (arg, "none") != 0)) E_FATAL("Unknown -agc argument: %s\n", arg); arg = (char *) cmd_ln_access ("-cmn"); if ((strcmp (arg, "current") != 0) && (strcmp (arg, "none") != 0)) E_FATAL("Unknown -cmn argument: %s\n", arg); }
kbcore_t *kbcore_init (float64 logbase, char *feattype, char *cmn, char *varnorm, char *agc, char *mdeffile, char *dictfile, char *fdictfile, char *compsep, char *lmfile, char *fillpenfile, float64 silprob, float64 fillprob, float64 langwt, float64 inspen, float64 uw, char *meanfile, char *varfile, float64 varfloor, char *mixwfile, float64 mixwfloor, char *subvqfile, char *tmatfile, float64 tmatfloor) { kbcore_t *kb; E_INFO("Initializing core models:\n"); kb = (kbcore_t *) ckd_calloc (1, sizeof(kbcore_t)); kb->fcb = NULL; kb->mdef = NULL; kb->dict = NULL; kb->dict2pid = NULL; kb->lm = NULL; kb->fillpen = NULL; kb->dict2lmwid = NULL; kb->mgau = NULL; kb->svq = NULL; kb->tmat = NULL; logs3_init (logbase); if (feattype) { if ((kb->fcb = feat_init (feattype, cmn, varnorm, agc)) == NULL) E_FATAL("feat_init(%s) failed\n", feattype); if (feat_n_stream(kb->fcb) != 1) E_FATAL("#Feature streams(%d) != 1\n", feat_n_stream(kb->fcb)); } if (mdeffile) { if ((kb->mdef = mdef_init (mdeffile)) == NULL) E_FATAL("mdef_init(%s) failed\n", mdeffile); } if (dictfile) { if (! compsep) compsep = ""; else if ((compsep[0] != '\0') && (compsep[1] != '\0')) { E_FATAL("Compound word separator(%s) must be empty or single character string\n", compsep); } if ((kb->dict = dict_init (kb->mdef, dictfile, fdictfile, compsep[0])) == NULL) E_FATAL("dict_init(%s,%s,%s) failed\n", dictfile, fdictfile ? fdictfile : "", compsep); } if (lmfile) { if ((kb->lm = lm_read (lmfile, langwt, inspen, uw)) == NULL) E_FATAL("lm_read(%s, %e, %e, %e) failed\n", lmfile, langwt, inspen, uw); } if (fillpenfile || (lmfile && kb->dict)) { if (! kb->dict) /* Sic */ E_FATAL("No dictionary for associating filler penalty file(%s)\n", fillpenfile); if ((kb->fillpen = fillpen_init (kb->dict, fillpenfile, silprob, fillprob, langwt, inspen)) == NULL) E_FATAL("fillpen_init(%s) failed\n", fillpenfile); } if (meanfile) { if ((! varfile) || (! mixwfile)) E_FATAL("Varfile or mixwfile not specified along with meanfile(%s)\n", meanfile); kb->mgau = mgau_init (meanfile, varfile, varfloor, mixwfile, mixwfloor, TRUE); if (kb->mgau == NULL) E_FATAL("gauden_init(%s, %s, %e) failed\n", meanfile, varfile, varfloor); if (subvqfile) { if ((kb->svq = subvq_init (subvqfile, varfloor, -1, kb->mgau)) == NULL) E_FATAL("subvq_init (%s, %e, -1) failed\n", subvqfile, varfloor); } } if (tmatfile) { if ((kb->tmat = tmat_init (tmatfile, tmatfloor)) == NULL) E_FATAL("tmat_init (%s, %e) failed\n", tmatfile, tmatfloor); } if (kb->dict && kb->lm) { /* Initialize dict2lmwid */ if ((kb->dict2lmwid = wid_dict_lm_map (kb->dict, kb->lm)) == NULL) E_FATAL("Dict/LM word-id mapping failed\n"); } if (kb->mdef && kb->dict) { /* Initialize dict2pid */ kb->dict2pid = dict2pid_build (kb->mdef, kb->dict); } /* ***************** Verifications ***************** */ E_INFO("Verifying models consistency:\n"); if (kb->fcb && kb->mgau) { /* Verify feature streams against gauden codebooks */ if (feat_stream_len(kb->fcb, 0) != mgau_veclen(kb->mgau)) E_FATAL("Feature streamlen(%d) != mgau streamlen(%d)\n", feat_stream_len(kb->fcb, 0), mgau_veclen(kb->mgau)); } if (kb->mdef && kb->mgau) { /* Verify senone parameters against model definition parameters */ if (kb->mdef->n_sen != mgau_n_mgau(kb->mgau)) E_FATAL("Mdef #senones(%d) != mgau #senones(%d)\n", kb->mdef->n_sen, mgau_n_mgau(kb->mgau)); } if (kb->mdef && kb->tmat) { /* Verify transition matrices parameters against model definition parameters */ if (kb->mdef->n_tmat != kb->tmat->n_tmat) E_FATAL("Mdef #tmat(%d) != tmatfile(%d)\n", kb->mdef->n_tmat, kb->tmat->n_tmat); if (kb->mdef->n_emit_state != kb->tmat->n_state) E_FATAL("Mdef #states(%d) != tmat #states(%d)\n", kb->mdef->n_emit_state, kb->tmat->n_state); } return kb; }