/**************************************************************************/ /* File: build_lattice.cc */ /**************************************************************************/ /* Project: Continuous Speech Recognition Search Algorithms */ /* Author: Neeraj Deshmukh, Aravind Ganapathiraju */ /* Class: EE 8993 Spring 1996 Date: April 25, 1996 */ /**************************************************************************/ /*======================================================================== This is the routine whihc builds the latice which has to be searched for the most probable hypothesis ========================================================================*/ /*------------------------------------------------------------------------ system and ISIP include files ------------------------------------------------------------------------*/ #include "test.h" void build_lattice_cc ( FILE *file_in, Grammar *grammar, HMM_Model **hmm_model,Score_Hyp *hypoth) { HMM_State *temp_state; Score_Hyp *temp_hyp; Score_Hyp *best_hyp = new Score_Hyp; Gram_State *state_ptr = new Gram_State (); String state_name; String temp_symbol; Trans_State *trans_ptr = NULL; int_4 time_index = 0; float_4 input_sample; float_4 score = 1; int_2 num_vec_len = ((hmm_model[0]->get_start_state_cc ())->get_mean_cc ())[0]->get_num_columns_cc (); // initialize the state_ptr to the first state in the language grammar // temp_state = hmm_model[0]->get_start_state_cc (); Gram_State *gram_states_ptr = grammar->get_states_ptr_cc (); // get the start state in the grammar // Gram_State *gram_start_state = grammar->get_start_state_cc (); trans_ptr = gram_start_state->get_transition_cc (); for (trans_ptr = trans_ptr->get_next_transition_cc (); trans_ptr != NULL; trans_ptr = trans_ptr->get_next_transition_cc ()) { state_name = trans_ptr->get_state_name_cc (); for (int_2 i = 0; i < 3; i++) { if (strcmp (state_name, hmm_model[i]->get_model_symbol_cc ()) == 0) { score = gram_start_state->get_transition_score_cc (state_name); hypothesize_cc ( file_in, hmm_model[i], hypoth, NULL, score, time_index , i ); rewind (file_in); } } } while (fscanf (file_in, "%f", &input_sample) != EOF ) { for (int_2 i = 1; i < num_vec_len; i++) { fscanf ( file_in,"%f", &input_sample ); } time_index++; best_hyp->set_path_score_cc (0.0); /* for ( temp_hyp = hypoth->get_next_hyp_cc (); temp_hyp != NULL; temp_hyp = temp_hyp->get_next_hyp_cc ()) { if (temp_hyp->get_timestamp_cc () == time_index) { temp_state = (HMM_State *)(temp_hyp->get_element_cc()); for ( int_2 i = 0; i < NUM_OF_MODELS; i++) { if (temp_state == hmm_model[i]->get_stop_state_cc ()) { // fprintf(stdout, "%s %ld %f\n", // hmm_model[temp_hyp->get_word_index_cc ()]-> // get_model_symbol_cc (), time_index, temp_hyp-> // get_path_score_cc ()); if ( temp_hyp->get_path_score_cc () > best_hyp->get_path_score_cc () ) { best_hyp = temp_hyp; } } } } } */ fprintf(stdout, "best :%s %f\n", hmm_model[best_hyp->get_word_index_cc ()] -> get_model_symbol_cc (), best_hyp->get_path_score_cc ()); fprintf(stdout, "\n"); state_ptr = gram_states_ptr-> find_state_cc (hmm_model[best_hyp->get_word_index_cc ()]-> get_model_symbol_cc () ); // now write all possible transitions // for (trans_ptr = (Trans_State *)state_ptr-> get_transition_cc (); trans_ptr != NULL; trans_ptr = (Trans_State *)trans_ptr-> get_next_transition_cc ()) { state_name = trans_ptr->get_state_name_cc (); for ( int_2 j = 0; j < NUM_OF_MODELS; j++) { temp_symbol = hmm_model[j]->get_model_symbol_cc (); if (strcmp (temp_symbol,state_name) == 0) { score = trans_ptr->get_transition_score_cc(); hypothesize_cc (file_in,hmm_model[j],hypoth, best_hyp,score,time_index, j ); } } } fseek (file_in, 3*(sizeof(float_4))*time_index, SEEK_SET); } //free memory // // delete best_hyp; // delete state_ptr; }