Add Kotlin and Java API for homophone replacer (#2166)
* Add Kotlin API for homonphone replacer * Add Java API for homonphone replacer
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
// Copyright 2025 Xiaomi Corporation
|
||||
|
||||
package com.k2fsa.sherpa.onnx;
|
||||
|
||||
public class HomophoneReplacerConfig {
|
||||
private final String dictDir;
|
||||
private final String lexicon;
|
||||
private final String ruleFsts;
|
||||
|
||||
private HomophoneReplacerConfig(Builder builder) {
|
||||
this.dictDir = builder.dictDir;
|
||||
this.lexicon = builder.lexicon;
|
||||
this.ruleFsts = builder.ruleFsts;
|
||||
}
|
||||
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public String getDictDir() {
|
||||
return dictDir;
|
||||
}
|
||||
|
||||
public String getLexicon() {
|
||||
return lexicon;
|
||||
}
|
||||
|
||||
public String getRuleFsts() {
|
||||
return ruleFsts;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private String dictDir = "";
|
||||
private String lexicon = "";
|
||||
private String ruleFsts = "";
|
||||
|
||||
public HomophoneReplacerConfig build() {
|
||||
return new HomophoneReplacerConfig(this);
|
||||
}
|
||||
|
||||
public Builder setDictDir(String dictDir) {
|
||||
this.dictDir = dictDir;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setLexicon(String lexicon) {
|
||||
this.lexicon = lexicon;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setRuleFsts(String ruleFsts) {
|
||||
this.ruleFsts = ruleFsts;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ package com.k2fsa.sherpa.onnx;
|
||||
public class OfflineRecognizerConfig {
|
||||
private final FeatureConfig featConfig;
|
||||
private final OfflineModelConfig modelConfig;
|
||||
private final HomophoneReplacerConfig hr;
|
||||
private final String decodingMethod;
|
||||
private final int maxActivePaths;
|
||||
private final String hotwordsFile;
|
||||
@@ -16,6 +17,7 @@ public class OfflineRecognizerConfig {
|
||||
private OfflineRecognizerConfig(Builder builder) {
|
||||
this.featConfig = builder.featConfig;
|
||||
this.modelConfig = builder.modelConfig;
|
||||
this.hr = builder.hr;
|
||||
this.decodingMethod = builder.decodingMethod;
|
||||
this.maxActivePaths = builder.maxActivePaths;
|
||||
this.hotwordsFile = builder.hotwordsFile;
|
||||
@@ -36,6 +38,7 @@ public class OfflineRecognizerConfig {
|
||||
public static class Builder {
|
||||
private FeatureConfig featConfig = FeatureConfig.builder().build();
|
||||
private OfflineModelConfig modelConfig = OfflineModelConfig.builder().build();
|
||||
private HomophoneReplacerConfig hr = HomophoneReplacerConfig.builder().build();
|
||||
private String decodingMethod = "greedy_search";
|
||||
private int maxActivePaths = 4;
|
||||
private String hotwordsFile = "";
|
||||
@@ -58,6 +61,11 @@ public class OfflineRecognizerConfig {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setHr(HomophoneReplacerConfig hr) {
|
||||
this.hr = hr;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setDecodingMethod(String decodingMethod) {
|
||||
this.decodingMethod = decodingMethod;
|
||||
return this;
|
||||
|
||||
@@ -10,6 +10,7 @@ public class OnlineRecognizerConfig {
|
||||
|
||||
private final OnlineCtcFstDecoderConfig ctcFstDecoderConfig;
|
||||
private final EndpointConfig endpointConfig;
|
||||
private final HomophoneReplacerConfig hr;
|
||||
private final boolean enableEndpoint;
|
||||
private final String decodingMethod;
|
||||
private final int maxActivePaths;
|
||||
@@ -25,6 +26,7 @@ public class OnlineRecognizerConfig {
|
||||
this.lmConfig = builder.lmConfig;
|
||||
this.ctcFstDecoderConfig = builder.ctcFstDecoderConfig;
|
||||
this.endpointConfig = builder.endpointConfig;
|
||||
this.hr = builder.hr;
|
||||
this.enableEndpoint = builder.enableEndpoint;
|
||||
this.decodingMethod = builder.decodingMethod;
|
||||
this.maxActivePaths = builder.maxActivePaths;
|
||||
@@ -49,6 +51,7 @@ public class OnlineRecognizerConfig {
|
||||
private OnlineLMConfig lmConfig = OnlineLMConfig.builder().build();
|
||||
private OnlineCtcFstDecoderConfig ctcFstDecoderConfig = OnlineCtcFstDecoderConfig.builder().build();
|
||||
private EndpointConfig endpointConfig = EndpointConfig.builder().build();
|
||||
private HomophoneReplacerConfig hr = HomophoneReplacerConfig.builder().build();
|
||||
private boolean enableEndpoint = true;
|
||||
private String decodingMethod = "greedy_search";
|
||||
private int maxActivePaths = 4;
|
||||
@@ -87,6 +90,11 @@ public class OnlineRecognizerConfig {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setHr(HomophoneReplacerConfig hr) {
|
||||
this.hr = hr;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setEnableEndpoint(boolean enableEndpoint) {
|
||||
this.enableEndpoint = enableEndpoint;
|
||||
return this;
|
||||
|
||||
Reference in New Issue
Block a user