Refactor Java API (#806)

This commit is contained in:
Fangjun Kuang
2024-04-24 18:41:48 +08:00
committed by GitHub
parent c7691650d7
commit c3a2e8a67c
42 changed files with 1008 additions and 968 deletions

View File

@@ -1,66 +1,95 @@
/*
* // Copyright 2022-2023 by zhaoming
*/
// Copyright 2022-2023 by zhaoming
// Copyright 2024 Xiaomi Corporation
package com.k2fsa.sherpa.onnx;
public class OnlineRecognizerConfig {
private final FeatureConfig featConfig;
private final OnlineModelConfig modelConfig;
private final EndpointConfig endpointConfig;
private final OnlineLMConfig lmConfig;
private final EndpointConfig endpointConfig;
private final boolean enableEndpoint;
private final String decodingMethod;
private final int maxActivePaths;
private final String hotwordsFile;
private final float hotwordsScore;
public OnlineRecognizerConfig(
FeatureConfig featConfig,
OnlineModelConfig modelConfig,
EndpointConfig endpointConfig,
OnlineLMConfig lmConfig,
boolean enableEndpoint,
String decodingMethod,
int maxActivePaths,
String hotwordsFile,
float hotwordsScore) {
this.featConfig = featConfig;
this.modelConfig = modelConfig;
this.endpointConfig = endpointConfig;
this.lmConfig = lmConfig;
this.enableEndpoint = enableEndpoint;
this.decodingMethod = decodingMethod;
this.maxActivePaths = maxActivePaths;
this.hotwordsFile = hotwordsFile;
this.hotwordsScore = hotwordsScore;
private OnlineRecognizerConfig(Builder builder) {
this.featConfig = builder.featConfig;
this.modelConfig = builder.modelConfig;
this.lmConfig = builder.lmConfig;
this.endpointConfig = builder.endpointConfig;
this.enableEndpoint = builder.enableEndpoint;
this.decodingMethod = builder.decodingMethod;
this.maxActivePaths = builder.maxActivePaths;
this.hotwordsFile = builder.hotwordsFile;
this.hotwordsScore = builder.hotwordsScore;
}
public OnlineLMConfig getLmConfig() {
return lmConfig;
}
public FeatureConfig getFeatConfig() {
return featConfig;
public static Builder builder() {
return new Builder();
}
public OnlineModelConfig getModelConfig() {
return modelConfig;
}
public EndpointConfig getEndpointConfig() {
return endpointConfig;
}
public static class Builder {
private FeatureConfig featConfig = FeatureConfig.builder().build();
private OnlineModelConfig modelConfig = OnlineModelConfig.builder().build();
private OnlineLMConfig lmConfig = OnlineLMConfig.builder().build();
private EndpointConfig endpointConfig = EndpointConfig.builder().build();
private boolean enableEndpoint = true;
private String decodingMethod = "greedy_search";
private int maxActivePaths = 4;
private String hotwordsFile = "";
private float hotwordsScore = 1.5f;
public boolean isEnableEndpoint() {
return enableEndpoint;
}
public OnlineRecognizerConfig build() {
return new OnlineRecognizerConfig(this);
}
public String getDecodingMethod() {
return decodingMethod;
}
public Builder setFeatureConfig(FeatureConfig featConfig) {
this.featConfig = featConfig;
return this;
}
public int getMaxActivePaths() {
return maxActivePaths;
public Builder setOnlineModelConfig(OnlineModelConfig modelConfig) {
this.modelConfig = modelConfig;
return this;
}
public Builder setOnlineLMConfig(OnlineLMConfig lmConfig) {
this.lmConfig = lmConfig;
return this;
}
public Builder setEndpointConfig(EndpointConfig endpointConfig) {
this.endpointConfig = endpointConfig;
return this;
}
public Builder setEnableEndpoint(boolean enableEndpoint) {
this.enableEndpoint = enableEndpoint;
return this;
}
public Builder setDecodingMethod(String decodingMethod) {
this.decodingMethod = decodingMethod;
return this;
}
public Builder setMaxActivePaths(int maxActivePaths) {
this.maxActivePaths = maxActivePaths;
return this;
}
public Builder setHotwordsFile(String hotwordsFile) {
this.hotwordsFile = hotwordsFile;
return this;
}
public Builder setHotwordsScore(float hotwordsScore) {
this.hotwordsScore = hotwordsScore;
return this;
}
}
}