From b3b33b54e5031a1d94eb3368365403c730147083 Mon Sep 17 00:00:00 2001 From: Administrator Date: Sat, 18 May 2024 14:43:06 +0800 Subject: [PATCH] =?UTF-8?q?2024.5.16=20=E6=B5=8B=E8=AF=95=E6=95=B4?= =?UTF-8?q?=E4=BD=93=E6=9E=84=E5=BB=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 2 +- decoder/asr_decoder.cc | 3 --- frontend/fbank.h | 2 +- frontend/feature_pipeline.cc | 4 +-- kaldi/fstext/lattice-weight.h | 16 +++++------ kaldi/lat/determinize-lattice-pruned.cc | 1 - post_processor/processor/wetext_processor.cc | 27 ++++++++++--------- .../processor/wetext_token_parser.cc | 1 + post_processor/utils/wetext_string.cc | 3 ++- utils/wn_string.cc | 2 +- 10 files changed, 30 insertions(+), 31 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4041b7a..e286fa5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,7 +33,7 @@ include(openfst) include_directories( ${OPENFST_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR} -# ${CMAKE_CURRENT_SOURCE_DIR}/kaldi + ${CMAKE_CURRENT_SOURCE_DIR}/kaldi ) # Build all libraries add_subdirectory(utils) diff --git a/decoder/asr_decoder.cc b/decoder/asr_decoder.cc index 7d99ecd..12a9430 100644 --- a/decoder/asr_decoder.cc +++ b/decoder/asr_decoder.cc @@ -15,10 +15,7 @@ #include "decoder/asr_decoder.h" -#include - #include -#include #include #include "utils/timer.h" diff --git a/frontend/fbank.h b/frontend/fbank.h index 066cd55..bc696e4 100644 --- a/frontend/fbank.h +++ b/frontend/fbank.h @@ -27,7 +27,7 @@ #endif namespace wenet { - +using namespace fst; // This code is based on kaldi Fbank implementation, please see // https://github.com/kaldi-asr/kaldi/blob/master/src/feat/feature-fbank.cc diff --git a/frontend/feature_pipeline.cc b/frontend/feature_pipeline.cc index 478ccb0..dda7a01 100644 --- a/frontend/feature_pipeline.cc +++ b/frontend/feature_pipeline.cc @@ -18,8 +18,8 @@ #include namespace wenet { - -FeaturePipeline::FeaturePipeline(const FeaturePipelineConfig& config) + using namespace fst; + FeaturePipeline::FeaturePipeline(const FeaturePipelineConfig& config) : config_(config), feature_dim_(config.num_bins), fbank_(config.num_bins, config.sample_rate, config.frame_length, diff --git a/kaldi/fstext/lattice-weight.h b/kaldi/fstext/lattice-weight.h index a211445..ed24777 100644 --- a/kaldi/fstext/lattice-weight.h +++ b/kaldi/fstext/lattice-weight.h @@ -401,8 +401,8 @@ template inline std::ostream& operator<<(std::ostream& strm, const LatticeWeightTpl& w) { LatticeWeightTpl::WriteFloatType(strm, w.Value1()); - CHECK(FST_FLAGS_fst_weight_separator.size() == 1); // NOLINT - strm << FST_FLAGS_fst_weight_separator[0]; // comma by default; + CHECK(FLAGS_fst_weight_separator.size() == 1); // NOLINT + strm << FLAGS_fst_weight_separator[0]; // comma by default; // may or may not be settable from Kaldi programs. LatticeWeightTpl::WriteFloatType(strm, w.Value2()); return strm; @@ -411,9 +411,9 @@ inline std::ostream& operator<<(std::ostream& strm, template inline std::istream& operator>>(std::istream& strm, LatticeWeightTpl& w1) { - CHECK(FST_FLAGS_fst_weight_separator.size() == 1); // NOLINT + CHECK(FLAGS_fst_weight_separator.size() == 1); // NOLINT // separator defaults to ',' - return w1.ReadNoParen(strm, FST_FLAGS_fst_weight_separator[0]); + return w1.ReadNoParen(strm, FLAGS_fst_weight_separator[0]); } // CompactLattice will be an acceptor (accepting the words/output-symbols), @@ -752,8 +752,8 @@ template inline std::ostream& operator<<( std::ostream& strm, const CompactLatticeWeightTpl& w) { strm << w.Weight(); - CHECK(FST_FLAGS_fst_weight_separator.size() == 1); // NOLINT - strm << FST_FLAGS_fst_weight_separator[0]; // comma by default. + CHECK(FLAGS_fst_weight_separator.size() == 1); // NOLINT + strm << FLAGS_fst_weight_separator[0]; // comma by default. for (size_t i = 0; i < w.String().size(); i++) { strm << w.String()[i]; if (i + 1 < w.String().size()) @@ -771,8 +771,8 @@ inline std::istream& operator>>( if (strm.fail()) { return strm; } - CHECK(FST_FLAGS_fst_weight_separator.size() == 1); // NOLINT - size_t pos = s.find_last_of(FST_FLAGS_fst_weight_separator); // normally "," + CHECK(FLAGS_fst_weight_separator.size() == 1); // NOLINT + size_t pos = s.find_last_of(FLAGS_fst_weight_separator); // normally "," if (pos == std::string::npos) { strm.clear(std::ios::badbit); return strm; diff --git a/kaldi/lat/determinize-lattice-pruned.cc b/kaldi/lat/determinize-lattice-pruned.cc index e390084..799d213 100644 --- a/kaldi/lat/determinize-lattice-pruned.cc +++ b/kaldi/lat/determinize-lattice-pruned.cc @@ -22,7 +22,6 @@ #include #include #include "fstext/determinize-lattice.h" // for LatticeStringRepository -#include "fstext/fstext-utils.h" #include "lat/lattice-functions.h" // for PruneLattice // #include "lat/minimize-lattice.h" // for minimization // #include "lat/push-lattice.h" // for minimization diff --git a/post_processor/processor/wetext_processor.cc b/post_processor/processor/wetext_processor.cc index 9dd484f..2256a48 100644 --- a/post_processor/processor/wetext_processor.cc +++ b/post_processor/processor/wetext_processor.cc @@ -15,21 +15,22 @@ #include "wetext_processor.h" #include "fst/string.h" namespace wetext { -Processor::Processor(const std::string& tagger_path, + using namespace fst; + Processor::Processor(const std::string& tagger_path, const std::string& verbalizer_path) { - tagger_.reset(StdVectorFst::Read(tagger_path)); - verbalizer_.reset(StdVectorFst::Read(verbalizer_path)); - compiler_ = std::make_shared>(fst::StringTokenType::BYTE); - printer_ = std::make_shared>(fst::StringTokenType::BYTE); + tagger_.reset(StdVectorFst::Read(tagger_path)); + verbalizer_.reset(StdVectorFst::Read(verbalizer_path)); + compiler_ = std::make_shared>(fst::StringTokenType::BYTE); + printer_ = std::make_shared>(fst::StringTokenType::BYTE); - if (tagger_path.find("_tn_") != tagger_path.npos) { - parse_type_ = ParseType::kTN; - } else if (tagger_path.find("_itn_") != tagger_path.npos) { - parse_type_ = ParseType::kITN; - } else { - LOG(FATAL) << "Invalid fst prefix, prefix should contain" - << " either \"_tn_\" or \"_itn_\"."; - } + if (tagger_path.find("_tn_") != tagger_path.npos) { + parse_type_ = ParseType::kTN; + } else if (tagger_path.find("_itn_") != tagger_path.npos) { + parse_type_ = ParseType::kITN; + } else { + LOG(FATAL) << "Invalid fst prefix, prefix should contain" + << " either \"_tn_\" or \"_itn_\"."; + } } std::string Processor::ShortestPath(const StdVectorFst& lattice) { diff --git a/post_processor/processor/wetext_token_parser.cc b/post_processor/processor/wetext_token_parser.cc index f64f9f3..22b6d1f 100644 --- a/post_processor/processor/wetext_token_parser.cc +++ b/post_processor/processor/wetext_token_parser.cc @@ -18,6 +18,7 @@ #include "../utils/wetext_string.h" namespace wetext { +using namespace fst; const char EOS[] = ""; const std::set UTF8_WHITESPACE = {" ", "\t", "\n", "\r", "\x0b\x0c"}; diff --git a/post_processor/utils/wetext_string.cc b/post_processor/utils/wetext_string.cc index 65bed35..b16729f 100644 --- a/post_processor/utils/wetext_string.cc +++ b/post_processor/utils/wetext_string.cc @@ -17,7 +17,8 @@ #include "wetext_log.h" namespace wetext { -const char* WHITESPACE = " \n\r\t\f\v"; + using namespace fst; + const char* WHITESPACE = " \n\r\t\f\v"; int UTF8CharLength(char ch) { int num_bytes = 1; diff --git a/utils/wn_string.cc b/utils/wn_string.cc index b66c7cc..4c02daa 100644 --- a/utils/wn_string.cc +++ b/utils/wn_string.cc @@ -21,7 +21,7 @@ #include "wn_utils.h" namespace wenet { - +using namespace fst; void SplitString(const std::string& str, std::vector* strs) { SplitStringToVector(Trim(str), " \t", true, strs); }