/**************************************************************************/ /* 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 = NULL; Score_Hyp *temp_hyp = NULL; Score_Hyp *best_hyp = new Score_Hyp (); Score_Hyp *init_hyp = NULL; Gram_State *state_ptr = NULL; Trans_State *trans_ptr = NULL; String state_name = ""; String temp_symbol = ""; int_4 time_index = 0; float_4 input_sample = 0; float_4 score = 1.0; hypoth->add_score_hyp_cc (NULL, NULL, 0, 0, 0); init_hyp = hypoth->get_next_hyp_cc (); 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 // 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 (); for (trans_ptr = gram_start_state->get_transition_cc (); trans_ptr != NULL; trans_ptr = trans_ptr->get_next_transition_cc ()) { // check all possible models that can start // for (int_2 ii = 0; ii < NUM_OF_MODELS; ii++) { if (strcmp (trans_ptr->get_state_name_cc (), hmm_model[ii]->get_model_symbol_cc ()) == 0) { hypothesize_cc ( file_in, hmm_model[ii], hypoth, init_hyp, score, time_index , ii); rewind (file_in); break; } } } // now read the inputs // while (fscanf (file_in, "%f", &input_sample) != EOF ) { for (int_2 i = 1; i < num_vec_len; i++) fscanf ( file_in,"%f", &input_sample ); // increment time index // time_index++; best_hyp->set_path_score_cc (0.0); // evaluate all hypotheses at this time frame // 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()); // check all models possible // for ( int_2 i = 0; i < NUM_OF_MODELS; i++) { if (temp_state == hmm_model[i]->get_stop_state_cc ()) { // re-adjust best path so far // if ( temp_hyp->get_path_score_cc () > best_hyp->get_path_score_cc () ) best_hyp = temp_hyp; } } } } // print the best path score // int_2 nn = best_hyp->get_word_index_cc (); // get to the new model states // state_ptr = gram_states_ptr->find_state_cc (hmm_model[nn]->get_model_symbol_cc ()); // now write all possible transitions from here // for (trans_ptr = state_ptr->get_transition_cc (); trans_ptr != NULL; trans_ptr = 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, num_vec_len * (sizeof(float_4)) * time_index, SEEK_SET); } }