Add Swift API for homophone replacer. (#2164)

This commit is contained in:
Fangjun Kuang
2025-04-29 18:50:41 +08:00
committed by GitHub
parent 4a7a974a04
commit 63d01a9534
5 changed files with 142 additions and 4 deletions

View File

@@ -128,6 +128,17 @@ func sherpaOnnxOnlineCtcFstDecoderConfig(
max_active: Int32(maxActive))
}
func sherpaOnnxHomophoneReplacerConfig(
dictDir: String = "",
lexicon: String = "",
ruleFsts: String = ""
) -> SherpaOnnxHomophoneReplacerConfig {
return SherpaOnnxHomophoneReplacerConfig(
dict_dir: toCPointer(dictDir),
lexicon: toCPointer(lexicon),
rule_fsts: toCPointer(ruleFsts))
}
func sherpaOnnxOnlineRecognizerConfig(
featConfig: SherpaOnnxFeatureConfig,
modelConfig: SherpaOnnxOnlineModelConfig,
@@ -144,7 +155,8 @@ func sherpaOnnxOnlineRecognizerConfig(
ruleFars: String = "",
blankPenalty: Float = 0.0,
hotwordsBuf: String = "",
hotwordsBufSize: Int = 0
hotwordsBufSize: Int = 0,
hr: SherpaOnnxHomophoneReplacerConfig = sherpaOnnxHomophoneReplacerConfig()
) -> SherpaOnnxOnlineRecognizerConfig {
return SherpaOnnxOnlineRecognizerConfig(
feat_config: featConfig,
@@ -162,7 +174,8 @@ func sherpaOnnxOnlineRecognizerConfig(
rule_fars: toCPointer(ruleFars),
blank_penalty: blankPenalty,
hotwords_buf: toCPointer(hotwordsBuf),
hotwords_buf_size: Int32(hotwordsBufSize)
hotwords_buf_size: Int32(hotwordsBufSize),
hr: hr
)
}
@@ -469,7 +482,8 @@ func sherpaOnnxOfflineRecognizerConfig(
hotwordsScore: Float = 1.5,
ruleFsts: String = "",
ruleFars: String = "",
blankPenalty: Float = 0.0
blankPenalty: Float = 0.0,
hr: SherpaOnnxHomophoneReplacerConfig = sherpaOnnxHomophoneReplacerConfig()
) -> SherpaOnnxOfflineRecognizerConfig {
return SherpaOnnxOfflineRecognizerConfig(
feat_config: featConfig,
@@ -481,7 +495,8 @@ func sherpaOnnxOfflineRecognizerConfig(
hotwords_score: hotwordsScore,
rule_fsts: toCPointer(ruleFsts),
rule_fars: toCPointer(ruleFars),
blank_penalty: blankPenalty
blank_penalty: blankPenalty,
hr: hr
)
}