Add C and CXX API for homophone replacer (#2156)
This commit is contained in:
@@ -153,6 +153,10 @@ static sherpa_onnx::OnlineRecognizerConfig GetOnlineRecognizerConfig(
|
||||
recognizer_config.rule_fsts = SHERPA_ONNX_OR(config->rule_fsts, "");
|
||||
recognizer_config.rule_fars = SHERPA_ONNX_OR(config->rule_fars, "");
|
||||
|
||||
recognizer_config.hr.dict_dir = SHERPA_ONNX_OR(config->hr.dict_dir, "");
|
||||
recognizer_config.hr.lexicon = SHERPA_ONNX_OR(config->hr.lexicon, "");
|
||||
recognizer_config.hr.rule_fsts = SHERPA_ONNX_OR(config->hr.rule_fsts, "");
|
||||
|
||||
if (config->model_config.debug) {
|
||||
#if __OHOS__
|
||||
SHERPA_ONNX_LOGE("%{public}s\n", recognizer_config.ToString().c_str());
|
||||
@@ -494,6 +498,10 @@ static sherpa_onnx::OfflineRecognizerConfig GetOfflineRecognizerConfig(
|
||||
recognizer_config.rule_fsts = SHERPA_ONNX_OR(config->rule_fsts, "");
|
||||
recognizer_config.rule_fars = SHERPA_ONNX_OR(config->rule_fars, "");
|
||||
|
||||
recognizer_config.hr.dict_dir = SHERPA_ONNX_OR(config->hr.dict_dir, "");
|
||||
recognizer_config.hr.lexicon = SHERPA_ONNX_OR(config->hr.lexicon, "");
|
||||
recognizer_config.hr.rule_fsts = SHERPA_ONNX_OR(config->hr.rule_fsts, "");
|
||||
|
||||
if (config->model_config.debug) {
|
||||
#if __OHOS__
|
||||
SHERPA_ONNX_LOGE("%{public}s\n", recognizer_config.ToString().c_str());
|
||||
|
||||
@@ -112,6 +112,12 @@ SHERPA_ONNX_API typedef struct SherpaOnnxOnlineCtcFstDecoderConfig {
|
||||
int32_t max_active;
|
||||
} SherpaOnnxOnlineCtcFstDecoderConfig;
|
||||
|
||||
SHERPA_ONNX_API typedef struct SherpaOnnxHomophoneReplacerConfig {
|
||||
const char *dict_dir;
|
||||
const char *lexicon;
|
||||
const char *rule_fsts;
|
||||
} SherpaOnnxHomophoneReplacerConfig;
|
||||
|
||||
SHERPA_ONNX_API typedef struct SherpaOnnxOnlineRecognizerConfig {
|
||||
SherpaOnnxFeatureConfig feat_config;
|
||||
SherpaOnnxOnlineModelConfig model_config;
|
||||
@@ -157,6 +163,7 @@ SHERPA_ONNX_API typedef struct SherpaOnnxOnlineRecognizerConfig {
|
||||
const char *hotwords_buf;
|
||||
/// byte size excluding the tailing '\0'
|
||||
int32_t hotwords_buf_size;
|
||||
SherpaOnnxHomophoneReplacerConfig hr;
|
||||
} SherpaOnnxOnlineRecognizerConfig;
|
||||
|
||||
SHERPA_ONNX_API typedef struct SherpaOnnxOnlineRecognizerResult {
|
||||
@@ -461,6 +468,8 @@ SHERPA_ONNX_API typedef struct SherpaOnnxOfflineRecognizerConfig {
|
||||
const char *rule_fsts;
|
||||
const char *rule_fars;
|
||||
float blank_penalty;
|
||||
|
||||
SherpaOnnxHomophoneReplacerConfig hr;
|
||||
} SherpaOnnxOfflineRecognizerConfig;
|
||||
|
||||
SHERPA_ONNX_API typedef struct SherpaOnnxOfflineRecognizer
|
||||
|
||||
@@ -99,6 +99,10 @@ OnlineRecognizer OnlineRecognizer::Create(
|
||||
c.hotwords_buf = config.hotwords_buf.c_str();
|
||||
c.hotwords_buf_size = config.hotwords_buf.size();
|
||||
|
||||
c.hr.dict_dir = config.hr.dict_dir.c_str();
|
||||
c.hr.lexicon = config.hr.lexicon.c_str();
|
||||
c.hr.rule_fsts = config.hr.rule_fsts.c_str();
|
||||
|
||||
auto p = SherpaOnnxCreateOnlineRecognizer(&c);
|
||||
return OnlineRecognizer(p);
|
||||
}
|
||||
@@ -261,6 +265,10 @@ OfflineRecognizer OfflineRecognizer::Create(
|
||||
|
||||
c.blank_penalty = config.blank_penalty;
|
||||
|
||||
c.hr.dict_dir = config.hr.dict_dir.c_str();
|
||||
c.hr.lexicon = config.hr.lexicon.c_str();
|
||||
c.hr.rule_fsts = config.hr.rule_fsts.c_str();
|
||||
|
||||
auto p = SherpaOnnxCreateOfflineRecognizer(&c);
|
||||
return OfflineRecognizer(p);
|
||||
}
|
||||
|
||||
@@ -55,6 +55,12 @@ struct OnlineCtcFstDecoderConfig {
|
||||
int32_t max_active = 3000;
|
||||
};
|
||||
|
||||
struct HomophoneReplacerConfig {
|
||||
std::string dict_dir;
|
||||
std::string lexicon;
|
||||
std::string rule_fsts;
|
||||
};
|
||||
|
||||
struct OnlineRecognizerConfig {
|
||||
FeatureConfig feat_config;
|
||||
OnlineModelConfig model_config;
|
||||
@@ -81,6 +87,7 @@ struct OnlineRecognizerConfig {
|
||||
float blank_penalty = 0;
|
||||
|
||||
std::string hotwords_buf;
|
||||
HomophoneReplacerConfig hr;
|
||||
};
|
||||
|
||||
struct OnlineRecognizerResult {
|
||||
@@ -280,6 +287,7 @@ struct SHERPA_ONNX_API OfflineRecognizerConfig {
|
||||
std::string rule_fsts;
|
||||
std::string rule_fars;
|
||||
float blank_penalty = 0;
|
||||
HomophoneReplacerConfig hr;
|
||||
};
|
||||
|
||||
struct SHERPA_ONNX_API OfflineRecognizerResult {
|
||||
|
||||
Reference in New Issue
Block a user