Support replacing homonphonic phrases (#2153)
This commit is contained in:
@@ -192,6 +192,13 @@ OnlineRecognizerImpl::OnlineRecognizerImpl(const OnlineRecognizerConfig &config)
|
||||
SHERPA_ONNX_LOGE("FST archives loaded!");
|
||||
}
|
||||
}
|
||||
|
||||
if (!config.hr.dict_dir.empty() && !config.hr.lexicon.empty() &&
|
||||
!config.hr.rule_fsts.empty()) {
|
||||
auto hr_config = config.hr;
|
||||
hr_config.debug = config.model_config.debug;
|
||||
hr_ = std::make_unique<HomophoneReplacer>(hr_config);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename Manager>
|
||||
@@ -239,6 +246,12 @@ OnlineRecognizerImpl::OnlineRecognizerImpl(Manager *mgr,
|
||||
} // for (; !reader->Done(); reader->Next())
|
||||
} // for (const auto &f : files)
|
||||
} // if (!config.rule_fars.empty())
|
||||
if (!config.hr.dict_dir.empty() && !config.hr.lexicon.empty() &&
|
||||
!config.hr.rule_fsts.empty()) {
|
||||
auto hr_config = config.hr;
|
||||
hr_config.debug = config.model_config.debug;
|
||||
hr_ = std::make_unique<HomophoneReplacer>(mgr, hr_config);
|
||||
}
|
||||
}
|
||||
|
||||
std::string OnlineRecognizerImpl::ApplyInverseTextNormalization(
|
||||
@@ -254,6 +267,15 @@ std::string OnlineRecognizerImpl::ApplyInverseTextNormalization(
|
||||
return text;
|
||||
}
|
||||
|
||||
std::string OnlineRecognizerImpl::ApplyHomophoneReplacer(
|
||||
std::string text) const {
|
||||
if (hr_) {
|
||||
text = hr_->Apply(text);
|
||||
}
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
#if __ANDROID_API__ >= 9
|
||||
template OnlineRecognizerImpl::OnlineRecognizerImpl(
|
||||
AAssetManager *mgr, const OnlineRecognizerConfig &config);
|
||||
|
||||
Reference in New Issue
Block a user