⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hmm_05.cc

📁 这是一个从音频信号里提取特征参量的程序
💻 CC
📖 第 1 页 / 共 5 页
字号:
    String identifier;    Filename input_file_name;            Filename input_ID;    String output;    String train_path;    String train_file;        Filename output_file_name;    Sdb output_sdb;        Vector<VectorFloat> data;    // load the hmm models from the model file    //    if (!load()) {      return Error::handle(name(), L"run: load hmm models",			   Error::ARG, __FILE__, __LINE__);    }    // set the search engine mode    //    search_engine_d.setInitialLevel(initial_level_d);        search_engine_d.setSearchMode(HierarchicalSearch::TRAIN);        // loop over the number of iterations    //    for (long iter = 0; iter < num_iterations_d; iter++) {      current_file_num = 0;      // print the current iteration      //      if (verbosity_d >= Integral::BRIEF) {	Console::increaseIndention();	output.assign(L"\nstarting iteration: ");	output.concat(iter);	Console::put(output);	Console::decreaseIndention();      }            // loop through each input utterance      //      for (sdb_a.gotoFirst(); sdb_a.getName(input_ID);	   sdb_a.gotoNext()) {	current_file_num++;	// get audio file path	//	identifier.assign(input_ID);	if (!audio_db_d.getRecord(identifier, input_file_name)) {	  return Error::handle(name(), L"initialize - unable to find audio file for identifier", Error::ARG, __FILE__, __LINE__);	    	}      			// print utterance processing information	//      	if (verbosity_d >= Integral::BRIEF) {	  Console::increaseIndention();	  output.assign(L"\nprocessing file ");	  output.concat(current_file_num);	  output.concat(L" (");	  output.concat(identifier);	  output.concat(L")");	  output.concat(L": ");	  output.concat(input_file_name);	  Console::put(output);	  Console::decreaseIndention();	    	}	// clear all data structures needed to decode	//	if (!search_engine_d.initializeLinearDecoder()) {	  return Error::handle(name(), L"linearDecoder", Error::ARG, __FILE__, __LINE__);	}		// initialize the top search level with the corresponding transcription	// we don't need a transcription database for segmented utterances	//	if (transcription_db_file_d.length() > 0) {	  initTranscription(identifier, current_file_num - 1);	}		// process the utterance file by the front end	//	fe_d.open(input_file_name);	// retrieve the all frames of data in advance	//	extractFeatures(data);	// decode the utterance	// 		if (!verify_d) {	  search_engine_d.linearDecoder(fe_d);	}	// pick up the best hypothesis and determine the utterance probability	//	String hypotheses;	double score = 0;	long num_frames = 0;	DoubleLinkedList<Trace> trace_path;		if (!search_engine_d.getHypotheses(hypotheses, alignment_level_d,					   score, num_frames, trace_path)) {	  // if no hypothesis found	  //	  hypotheses.clear();	  trace_path.clear();	  	  if ((!verify_d) && (verbosity_d >= Integral::BRIEF)) {	    	    // print the warning message	    //	    Console::increaseIndention();	    Console::put(L"\nno hypothesis found");	    Console::decreaseIndention();	  }	}	else {	  num_valid_files++;	  total_num_frames += num_frames;	}       	// compute the forward probabilities (alphas)	//	trellis_d = (BiGraph<TrainNode>*)NULL;	trellis_d = search_engine_d.computeForwardBackward(data, beta_threshold_d);	// determine the utterance probability here again	//	computeUtterProb(score);	// print utterance probability	//      	if (verbosity_d >= Integral::BRIEF) {	  Console::increaseIndention();	  output.assign(L"\naverage utterance probability: ");	  output.concat(score/num_frames);	  output.concat(L", number of frames: ");	  output.concat(num_frames);	  Console::put(output);	  Console::decreaseIndention();	    	}      		// accumulate the statistics	//	accumulate(score, data);	// close the front end processing	//	fe_d.close();      } // end of looping through the input utterances      // update the models using the accumulated statistics      //      update();      // reset the statistical model and state transition accumulators      //      if (iter < (long)num_iterations_d - 1) {	resetAccumulators();      }    } // end of looping over the number of iterations        // clear all data structures needed to decode    //    if (!search_engine_d.initializeLinearPartial()) {      return Error::handle(name(), L"linearDecoder", Error::ARG, __FILE__, __LINE__);    }    // clear the top level    //    search_engine_d.getSearchLevels()((long)initial_level_d).clear();    // restore the top-level subgraph of the hierarchy    //        LanguageModel lm_model;    if (!lm_model.load(lm_model_file_d, ac_model_file_d, (long)initial_level_d,		       search_engine_d.getSearchLevels())) {      return Error::handle(name(), L"load: loading model file",			   Error::ARG, __FILE__, __LINE__);    }        // write the models to file    //    if (!store()) {      return Error::handle(name(), L"linearDecoder", Error::ARG, __FILE__, __LINE__);    }        // clean up all memory    //    search_engine_d.clear();    // print the number of successfully processed files    //    if (verbosity_d >= Integral::BRIEF) {      output.assign(L"\nprocessed ");      output.concat(num_valid_files);      output.concat(L" file(s) successfully, attempted ");      output.concat(current_file_num);      output.concat(L" file(s), ");      output.concat(total_num_frames);      output.concat(L" frame(s)\n");          Console::put(output);    }    } // end of TRAIN using BAUM_WELCH and NONE  // branch on ADAPT_DECODE using SUPERVISED and INCREMENTAL  // does not support streaming input.  //  else if (algorithm_d == ADAPT_DECODE && !stream_d &&	   adapt_supervision_mode_d == SUPERVISED &&	   adapt_sequence_mode_d == INCREMENTAL) {    // declare local variables    //    long num_valid_files = 0;    long current_file_num = 0;    long total_num_frames = 0;    String identifier;    Filename input_file_name;            Filename input_ID;    String output;    String train_path;    String train_file;        Filename output_file_name;    Sdb output_sdb;        Vector<VectorFloat> data;    // load the hmm models from the model file    //    if (!load()) {      return Error::handle(name(), L"run: load hmm models",			   Error::ARG, __FILE__, __LINE__);    }    // set the search engine mode    //        search_engine_d.setSearchMode(HierarchicalSearch::TRAIN);        // loop over the number of iterations    //    for (long iter = 0; iter < num_iterations_d; iter++) {      current_file_num = 0;      // print the current iteration      //      if (verbosity_d >= Integral::BRIEF) {	Console::increaseIndention();	output.assign(L"\nstarting iteration: ");	output.concat(iter);	Console::put(output);	Console::decreaseIndention();      }            // loop through each input utterance      //      for (sdb_a.gotoFirst(); sdb_a.getName(input_ID);	   sdb_a.gotoNext()) {	current_file_num++;	// get audio file path	//	identifier.assign(input_ID);	if (!audio_db_d.getRecord(identifier, input_file_name)) {	  input_ID.debug(L"input_ID");	  return Error::handle(name(), L"initialize - unable to find audio file for identifier", Error::ARG, __FILE__, __LINE__);	    	}      			// print utterance processing information	//      	if (verbosity_d >= Integral::BRIEF) {	  Console::increaseIndention();	  output.assign(L"\nprocessing file ");	  output.concat(current_file_num);	  output.concat(L" (");	  output.concat(identifier);	  output.concat(L")");	  output.concat(L": ");	  output.concat(input_file_name);	  Console::put(output);	  Console::decreaseIndention();	    	}	// clear all data structures needed to decode	//	if (!search_engine_d.initializeLinearDecoder()) {	  return Error::handle(name(), L"linearDecoder", Error::ARG, __FILE__, __LINE__);	}		// initialize the top search level with the corresponding transcription	// we don't need a transcription database for segmented utterances	//	if (transcription_db_file_d.length() > 0) {	  initTranscription(identifier, current_file_num - 1);	}		// process the utterance file by the front end	//	fe_d.open(input_file_name);	// retrieve the all frames of data in advance	//	extractFeatures(data);	// decode the utterance	// 		if (!verify_d) {	  search_engine_d.linearDecoder(fe_d);	}	// pick up the best hypothesis and determine the utterance probability	//	String hypotheses;	double score = 0;	long num_frames = 0;	DoubleLinkedList<Trace> trace_path;		if (!search_engine_d.getHypotheses(hypotheses, alignment_level_d,					   score, num_frames, trace_path)) {	  // if no hypothesis found	  //	  hypotheses.clear();	  trace_path.clear();	  	  if ((!verify_d) && (verbosity_d >= Integral::BRIEF)) {	    	    // print the warning message	    //	    Console::increaseIndention();	    Console::put(L"\nno hypothesis found");	    Console::decreaseIndention();	  }	}	else {	  num_valid_files++;	  total_num_frames += num_frames;	}       	// compute the forward probabilities (alphas)	//	trellis_d = (BiGraph<TrainNode>*)NULL;	trellis_d = search_engine_d.computeForwardBackward(data, beta_threshold_d);	// determine the utterance probability here again	//	computeUtterProb(score);	// print utterance probability	//      	if (verbosity_d >= Integral::BRIEF) {	  Console::increaseIndention();	  output.assign(L"\naverage utterance probability: ");	  output.concat(score/num_frames);	  output.concat(L", number of frames: ");	  output.concat(num_frames);	  Console::put(output);	  Console::decreaseIndention();	    	}      		// accumulate the statistics	//	accumulate(score, data);	// close the front end processing	//	fe_d.close();      } // end of looping through the input utterances      // get vector of statistical models      //      Vector<StatisticalModel>& stat_models =	search_engine_d.getSearchLevel((long)num_levels_d - 1).	getStatisticalModels();        // adapt the models using the accumulated statistics      //      adapt(stat_models);      // reset the statistical model and state transition accumulators      //      if (iter < (long)num_iterations_d - 1) {	resetAccumulators();      }    } // end of looping over the number of iterations        // clear all data structures needed to decode    //    if (!search_engine_d.initializeLinearPartial()) {      return Error::handle(name(), L"linearDecoder", Error::ARG, __FILE__, __LINE__);    }    // clear the top level    //    search_engine_d.getSearchLevels()(0).clear();        // restore the top-level subgraph of the hierarchy    //        LanguageModel lm_model;    if (!lm_model.load(lm_model_file_d, ac_model_file_d, 0,		       search_engine_d.getSearchLevels())) {      return Error::handle(name(), L"load: loading model file",			   Error::ARG, __FILE__, __LINE__);    }    // write the models to file    //    if (!store()) {      return Error::handle(name(), L"linearDecoder", Error::ARG, __FILE__, __LINE__);    }      // clean up all memory    //    search_engine_d.clear();    // print the number of successfully processed files    //    if (verbosity_d >= Integral::BRIEF) {      output.assign(L"\nprocessed ");      output.concat(num_valid_files);      output.concat(L" file(s) successfully, attempted ");      output.concat(current_file_num);      output.concat(L" file(s), ");      output.concat(total_num_frames);      output.concat(L" frame(s)\n");          Console::put(output);    }    } // ADAPT_DECODE using SUPERVISED and INCREMENTAL    // branch on the UNKNOWN options  //  else {        return Error::handle(name(), L"invalid algorithm and/or implementation", Error::ARG, __FILE__, __LINE__);  }    // gracefully exit  //  return true;  }// method: grammarDecoder//// arguments://  Sdb& sdb: (input) signal data base to run on//// return: a boolean value indicating status//// this is the run method for a grammar decoder//boolean HiddenMarkovModel::grammarDecoder(Sdb& sdb_a) {  // branch on the CONTEXT_GENERATION using SYMBOL_GENERATION  // does not support streaming input.  //  if (algorithm_d == CONTEXT_GENERATION && !stream_d &&      implementation_d == SYMBOL_GENERATION && function_mode_d == NONE) {    // declare local variables    //    long num_valid_files = 0;    long current_file_num = 0;    long total_num_frames = 0;    String identifier;    Filename input_file_name;        String output;        Filename input_ID;    // load the hmm models from the model file    //    if (!load()) {      return Error::handle(name(), L"run: load hmm models",			   Error::ARG, __FILE__, __LINE__);    }    // set the se

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -