📄 hmm_05.cc
字号:
input_sof.close(); // clean up all memory // search_engine_d.clear(); } // end of CONTEXT_GENERATION using SYMBOL_GENERATION // branch on the CONTEXT_GENERATION using MODEL_GENERATION // does not support streaming input. // else if (algorithm_d == CONTEXT_GENERATION && !stream_d && implementation_d == MODEL_GENERATION) { // load the hmm models from the model file // if (!load()) { return Error::handle(name(), L"grammarDecoder - unable to load models", Error::ARG, __FILE__, __LINE__); } // generate context for all levels specified // for (long curr_level = 0; curr_level < num_levels_d; curr_level++) { SearchLevel& level = search_engine_d.getSearchLevel(curr_level); if (curr_level == (long)context_level_d) { long left_order = level.getLeftContext(); long right_order = level.getRightContext(); if (!level.generateContextMapping(left_order, right_order, context_list_d, search_engine_d.getSearchLevels(), true)) { return Error::handle(name(), L"grammarDecoder", Error::ARG, __FILE__, __LINE__); } } } // write the models to file // if (!store()) { return Error::handle(name(), L"grammarDecoder - unable to store models", Error::ARG, __FILE__, __LINE__); } // clean up memory // search_engine_d.clear(); } // end of CONTEXT_GENERATION using MODEL_GENERATION // branch on DECODE/FORCED_ALIGNMENT using VITERBI // else if ((algorithm_d == DECODE && implementation_d == VITERBI) || (algorithm_d == FORCED_ALIGNMENT && implementation_d == VITERBI)) { // 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; Filename output_file_name; Sdb output_sdb; Vector<VectorFloat> data; TranscriptionDatabase trans_db; // 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::DECODE); // when the output mode is FILE // File total_output_file; if (output_mode_d == FILE) { if (output_file_d.length() > 0) { if (verbosity_d >= Integral::BRIEF) { Console::increaseIndention(); output.assign(L"\nopening the output file: "); output.concat(output_file_d); Console::put(output); Console::decreaseIndention(); } // open the output file for the utterance hypotheses // if (!total_output_file.open(output_file_d, File::WRITE_ONLY)) { return Error::handle(name(), L"run: opening output file", Error::ARG, __FILE__, __LINE__); } else { total_output_file.close(); } } } // when the output mode is DATABASE // Sof output_db_sof; if (output_mode_d == DATABASE) { if (output_file_d.length() > 0) { if (verbosity_d >= Integral::BRIEF) { Console::increaseIndention(); output.assign(L"\nopening the output file: "); output.concat(output_file_d); Console::put(output); Console::decreaseIndention(); } // open the output file for the utterance hypotheses (TEXT) // if (output_type_d == TEXT) { if (!output_db_sof.open(output_file_d, File::WRITE_ONLY)) { return Error::handle(name(), L"run: opening output file", Error::ARG, __FILE__, __LINE__); } else { // read all identifiers form the sdb object // Vector<String> identifier_keys; identifier_keys.setCapacity(sdb_a.length()); for (sdb_a.gotoFirst(); sdb_a.getName(input_ID); sdb_a.gotoNext()) { identifier.assign(input_ID); identifier_keys.concat(identifier); } trans_db.storePartial(output_db_sof, 0, identifier_keys); } } // end of output type TEXT // open the output file for the utterance hypotheses (BINARY) // if (output_type_d == BINARY) { if (!output_db_sof.open(output_file_d, File::WRITE_ONLY, File::BINARY)) { return Error::handle(name(), L"run: opening output file", Error::ARG, __FILE__, __LINE__); } else { // read all identifiers form the sdb object // Vector<String> identifier_keys; identifier_keys.setCapacity(sdb_a.length()); for (sdb_a.gotoFirst(); sdb_a.getName(input_ID); sdb_a.gotoNext()) { identifier.assign(input_ID); identifier_keys.concat(identifier); } trans_db.storePartial(output_db_sof, 0, identifier_keys); } } // end of output type BINARY } } // loop through the input utterances // for (sdb_a.gotoFirst(); sdb_a.getName(input_ID); sdb_a.gotoNext()) { current_file_num++; // if input is streaming, set input_file_name to STREAM_FILE // if (stream_d) { input_file_name.assign(File::STREAM_FILE); } // otherwise get the file path // else { // 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(); } // initialize the decoder // if (!search_engine_d.initializeLinearDecoder()) { return Error::handle(name(), L"linearDecoder", Error::ARG, __FILE__, __LINE__); } // 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); } fe_d.close(); // pick up the best hypothesis and its parameters // 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; } // print the detailed info about the hypothesis // if (verbosity_d >= Integral::BRIEF) { Console::increaseIndention(); Console::increaseIndention(); output.assign(L"\nhyp: "); output.concat(hypotheses); output.concat(L"\nscore: "); output.concat(score); output.concat(L" frames: "); output.concat(num_frames); Console::put(output); Console::decreaseIndention(); Console::decreaseIndention(); } if (output_mode_d == TRANSFORM) { // transform the input file and its path to the output file // sdb_a.transformName(output_file_name, input_file_name); // open the output file and write best hypothesis // File output_file; if (!output_file.open(output_file_name, File::WRITE_ONLY)) { return Error::handle(name(), L"linearDecoder - error opening output file", Error::ARG, __FILE__, __LINE__); } output_file.put(hypotheses); // close the output file // output_file.close(); } if (output_mode_d == DATABASE) { String name_00(identifier); String gtype_00(identifier); AnnotationGraph output_graph(name_00, gtype_00); // convert the best search path to an annotation graph // if (!createAnnotationGraph(output_graph, trace_path)) { return Error::handle(name(), L"linearDecoder", Error::ARG, __FILE__, __LINE__); } // write the annotation graph to the database // trans_db.storePartial(output_db_sof, current_file_num - 1, output_graph); } if (output_mode_d == FILE) { // output the best hypothesis // output.assign(hypotheses); if ((long)alignment_level_d < 0) { output.concat(L" ("); output.concat(input_ID); output.concat(L")\n"); } if (output_file_d.length() != 0) { total_output_file.open(output_file_d, File::APPEND_PLUS); total_output_file.put(output); total_output_file.close(); } else { if (verbosity_d < Integral::BRIEF) { Console::increaseIndention(); Console::increaseIndention(); Console::put(output); Console::decreaseIndention(); Console::decreaseIndention(); } } } if (output_mode_d == LIST) { // output the hypothesis to the corresponding file // from the output list // boolean more_files; if (current_file_num == 1) { // read output files list into signal database // Sof output_list_file; if (!output_list_file.open(output_list_d)) { return Error::handle(name(), L"linearDecoder - error opening output list", Error::ARG, __FILE__, __LINE__); } output_sdb.read(output_list_file, 0); output_list_file.close(); more_files = output_sdb.gotoFirst(); } else { // move to the next output file // more_files = output_sdb.gotoNext(); } if (!more_files) { return Error::handle(name(), L"linearDecoder - insufficient output files in the output list", Error::ARG, __FILE__, __LINE__); } // open the next output file and write the best hypothesis // output_sdb.getName(output_file_name); File output_file; if (!output_file.open(output_file_name, File::WRITE_ONLY)) { Console::increaseIndention(); output.assign(L"\ncannot open output file: "); output.concat(output_file_name); Console::put(output); Console::decreaseIndention(); } else { output_file.put(hypotheses); output_file.put(L"\n"); output_file.close(); } } } // end of looping through the input utterances // clean up all memory // search_engine_d.clear(); // close database files // if (output_mode_d == DATABASE) { output_db_sof.close(); } // close the audio database (optional) // if (audio_db_file_d.length() > 0) { if (!audio_db_d.close()) { return Error::handle(name(), L"linearDecoder", Error::ARG, __FILE__, __LINE__); } } // close the transcription database (optional) // if (transcription_db_file_d.length() > 0) { if (!transcription_db_d.close()) { return Error::handle(name(), L"linearDecoder", Error::ARG, __FILE__, __LINE__); } } // 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 DECODE using VITERBI // branch on DECODE using STACK // else if (algorithm_d == DECODE && implementation_d == STACK) { // 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; 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__); } // open the output file // File total_output_file; if (output_mode_d == FILE) { if (output_file_d.length() > 0) { if (verbosity_d >= Integral::BRIEF) { Console::increaseIndention(); output.assign(L"\nopening the output file: "); output.concat(output_file_d); Console::put(output); Console::decreaseIndention(); } // open the output file for the utterance hypotheses // if (!total_output_file.open(output_file_d, File::WRITE_ONLY)) { return Error::handle(name(), L"run: opening output file", Error::ARG, __FILE__, __LINE__);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -