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

📄 lm_08.cc

📁 这是一个从音频信号里提取特征参量的程序
💻 CC
📖 第 1 页 / 共 2 页
字号:
// file: $isip/class/asr/LanguageModel/lm_08.cc// version: $Id: lm_08.cc,v 1.28 2003/03/18 17:45:33 huang Exp $//// isip include files//#include "LanguageModel.h"// method: load//// arguments://        const String& lm_model_file_a: (input) model file //        const String& ac_model_file_a: (input) statistical model file//// return: a boolean value indicating status//// This method reads three levels of language models from input model file// in JSGF format and statistical models from input statistical model file,// then convert the JSGF models to ISIP internal Sof format and load// these models into a set of class-protected search levels//boolean LanguageModel::load(const String& lm_model_file_a,			    const String& ac_model_file_a) {    // call another function  //  return load(lm_model_file_a, ac_model_file_a, search_levels_d);}// method: load//// arguments://         const String& lm_lm_model_file_a: (input) model file//         const String& ac_lm_model_file_a: (input) statistical model file//         const Vector<SearchLevel>& search_levels_a: (output) search levels//// return: a boolean value indicating status//// This method reads three levels of language models from input model file// in JSGF format and statistical models from input statistical model file,// then convert the JSGF models to ISIP internal Sof format and load// these models into a set of user-input search levels instead of the// class-protected search levels//boolean LanguageModel::load(const String& lm_model_file_a,			    const String& ac_model_file_a,			    Vector<SearchLevel>& search_levels_a) {    // First, check the format of the input model file  //  // boolean variables indicating input file format  //  boolean sof_format = true;  boolean jsgf_format = true;    // open the input sof file  //  Sof input;  if(!input.open(lm_model_file_a, File::READ_ONLY)) {    return Error::handle(lm_model_file_a, L"open", Error::TEST,			 __FILE__, __LINE__);  }  // check if the input lm_model_file_a is in ISIP Sof NATIVE format by  // searching the number of levels by checking the search_symbols tag   //  long sof_tag_counter = 0;  for(long tag = input.first(L"search_symbols"); tag != Sof::NO_TAG;            tag = input.next(L"search_symbols", tag)) {    // count the number of JSGF tags    //    sof_tag_counter++;  }  // if no search_symbols tag has been found, the file must not be  // in JSGF format  //  if(sof_tag_counter == 0) {        sof_format = false;  }  // Then, check if the input lm_model_file_a is in JSGF format by  // searching from the input file the number of JSGF tags  //  // declare a counter to count the number of JSGF tags  //  long jsgf_tag_counter = 0;  for(long tag = input.first(L"JSGF"); tag != Sof::NO_TAG;      tag = input.next(L"JSGF", tag)) {        // count the number of JSGF tags    //    jsgf_tag_counter++;  }  // if no JSGF tag has been found, the file must not be in JSGF format  //  if(jsgf_tag_counter == 0) {    jsgf_format = false;  }      // close the input file  //  input.close();      // if the file format is neither Sof nor JSGF, return error  //  if (((!sof_format) && (!jsgf_format)) ||      ((sof_format) && (jsgf_format))) {        return Error::handle(name(), L"the format of input model file is not acceptable", Error::TEST, __FILE__, __LINE__);  }    // Second, set number of search levels  //  if(sof_format) {    // set num of levels    //    if(num_level_d == 0) {      num_level_d = sof_tag_counter;    }  }  if(jsgf_format) {    // set num of levels    //    if(num_level_d == 0) {      num_level_d = jsgf_tag_counter - 1;    }  }  // close the file  //  input.close();        // also resize search_levels_a to match the number of levels obtained from  // model_file  //  search_levels_a.setLength(num_level_d);  search_levels_a.setCapacity(num_level_d);  search_levels_d.setLength(num_level_d);  search_levels_d.setCapacity(num_level_d);    // loop through the levels  //  for (long i=0; i<num_level_d; i++) {    // load each level    //    load(lm_model_file_a, ac_model_file_a, i, search_levels_a);        } // end: for (long i=0; i<num_files_a; i++)  // exit gracefully  //  return true;}// method: load//// arguments://         const String& lm_model_file_a: (input) model file//         const Vector<SearchLevel>& search_levels_a: (input) search levels//         long level_index_a: (input) index of a single search level//         const String& ac_model_file_a: (input) statistical model file//// return: a boolean value indicating status//// This method reads data from input model file and update a single// search level in a set of user-input search levels according to input index//boolean LanguageModel::load(const String& lm_model_file_a,			    const String& ac_model_file_a,			    const long level_index_a,			    			    Vector<SearchLevel>& search_levels_a) {    // First, check the format of the input model file  //  // boolean variables indicating input file format  //  boolean sof_format = true;  boolean jsgf_format = true;    // open the input sof file  //  Sof input;  if(!input.open(lm_model_file_a, File::READ_ONLY)) {    return Error::handle(lm_model_file_a, L"open", Error::TEST,			 __FILE__, __LINE__);  }  // check if the input lm_model_file_a is in ISIP Sof NATIVE format by  // searching the number of levels by checking the search_symbols tag   //  long sof_tag_counter = 0;  for(long tag = input.first(L"search_symbols"); tag != Sof::NO_TAG;            tag = input.next(L"search_symbols", tag)) {    // count the number of JSGF tags    //    sof_tag_counter++;  }  // if no search_symbols tag has been found, the file must not be  // in JSGF format  //  if(sof_tag_counter == 0) {        sof_format = false;  }  // Then, check if the input lm_model_file_a is in JSGF format by  // searching from the input file the number of JSGF tags  //  // declare a counter to count the number of JSGF tags  //  long jsgf_tag_counter = 0;  for(long tag = input.first(L"JSGF"); tag != Sof::NO_TAG;      tag = input.next(L"JSGF", tag)) {        // count the number of JSGF tags    //    jsgf_tag_counter++;  }  // if no JSGF tag has been found, the file must not be in JSGF format  //  if(jsgf_tag_counter == 0) {    jsgf_format = false;  }      // close the input file  //  input.close();      // if the file format is neither Sof nor JSGF, return error  //  if (((!sof_format) && (!jsgf_format)) ||      ((sof_format) && (jsgf_format))) {        return Error::handle(name(), L"the format of input model file is not acceptable", Error::ARG, __FILE__, __LINE__);  }  // Second, make sure the input level index exists in the model file  //  if (sof_format) {       if (level_index_a >= sof_tag_counter) {      return Error::handle(name(), L"load: the level index not found in model file", Error::ARG, __FILE__, __LINE__);    }  }  if(jsgf_format) {    if(level_index_a >= jsgf_tag_counter - 1) {      return Error::handle(name(), L"load: the level index not found in model file", Error::ARG, __FILE__, __LINE__);    }      }    // set correct level index  //  search_levels_a(level_index_a).setLevelIndex(level_index_a);  // Third, load in the level of models  //  // if the format is ISIP Sof  //  if(sof_format) {        // open the input sof file    //    if (!input.open(lm_model_file_a, File::READ_ONLY)) {      return Error::handle(lm_model_file_a, L"open", Error::TEST,			   __FILE__, __LINE__);    }        // load the search level according to the input level index    //    if (!search_levels_a(level_index_a).load(input, level_index_a)) {      return Error::handle(name(), L"load: loading search level",			   Error::ARG, __FILE__, __LINE__);    }        // close the input model file    //    input.close();      } // end: if(sof_format)    // if the file is in JSGF format  //  if (jsgf_format) {        // get user-defined ISIP graph endings    //    if(!input.open(lm_model_file_a, File::READ_ONLY)) {      return Error::handle(lm_model_file_a, L"open", Error::TEST,			   __FILE__, __LINE__);    }        // read in the user settings for the ISIP graph    // starting and terminal symbols    //    setGraphEndings(input);    boolean context_map = false;        // do we have context mapping ?    //    if ( level_index_a > 0	 && search_levels_a(level_index_a-1).getContextMap().length() > 0 ){      context_map = true;    }    // read non grammars    //    loadNonGrammars(input, search_levels_a, level_index_a);          // read grammars    //    if ( context_map || level_index_a == 0 ){      read(input, L"JSGF", search_levels_a(level_index_a), context_map);    }    else{      read(input, L"JSGF", search_levels_a(level_index_a), context_map,	   &(search_levels_a(level_index_a - 1).getSymbolTable()));    }    // read the context mapping    //    loadContextMapping(input, L"JSGF", search_levels_a(level_index_a),		       level_index_a);        // load ngram models    //    search_levels_a(level_index_a).loadNSymbolModel();    // close the file    //    input.close();        } // end: if (jsgf_format)  // load in the statistical models to the last level if needed  //  if (level_index_a == (num_level_d - 1) && ac_model_file_a.length() != 0) {    Sof acoustic_model_sof;    if(!acoustic_model_sof.open(ac_model_file_a, File::READ_ONLY)) {      return Error::handle(ac_model_file_a, L"open", Error::TEST,			   __FILE__, __LINE__);    }          // load statistical models    //    search_levels_a(level_index_a).loadStatisticalModels(acoustic_model_sof, level_index_a);        // set statistical models to the search nodes in the last level    //    if(!search_levels_a(level_index_a).connectStatisticalModels()) {      return Error::handle(name(), L"load", Error::ARG, __FILE__, __LINE__);    }      // close the statistical model file

⌨️ 快捷键说明

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