正在显示
15 个修改的文件
包含
581 行增加
和
552 行删除
java-api-examples/.gitignore
0 → 100644
| @@ -9,10 +9,11 @@ LIB_FILES = \ | @@ -9,10 +9,11 @@ LIB_FILES = \ | ||
| 9 | $(LIB_SRC_DIR)/OnlineLMConfig.java \ | 9 | $(LIB_SRC_DIR)/OnlineLMConfig.java \ |
| 10 | $(LIB_SRC_DIR)/OnlineTransducerModelConfig.java \ | 10 | $(LIB_SRC_DIR)/OnlineTransducerModelConfig.java \ |
| 11 | $(LIB_SRC_DIR)/OnlineParaformerModelConfig.java \ | 11 | $(LIB_SRC_DIR)/OnlineParaformerModelConfig.java \ |
| 12 | + $(LIB_SRC_DIR)/OnlineZipformer2CtcModelConfig.java \ | ||
| 12 | $(LIB_SRC_DIR)/OnlineModelConfig.java \ | 13 | $(LIB_SRC_DIR)/OnlineModelConfig.java \ |
| 13 | $(LIB_SRC_DIR)/OnlineRecognizerConfig.java \ | 14 | $(LIB_SRC_DIR)/OnlineRecognizerConfig.java \ |
| 14 | $(LIB_SRC_DIR)/OnlineStream.java \ | 15 | $(LIB_SRC_DIR)/OnlineStream.java \ |
| 15 | - $(LIB_SRC_DIR)/OnlineRecognizer.java \ | 16 | + $(LIB_SRC_DIR)/OnlineRecognizer.java |
| 16 | 17 | ||
| 17 | WEBSOCKET_DIR:= ./src/websocketsrv | 18 | WEBSOCKET_DIR:= ./src/websocketsrv |
| 18 | WEBSOCKET_FILES = \ | 19 | WEBSOCKET_FILES = \ |
| @@ -42,10 +43,10 @@ vpath %.java src | @@ -42,10 +43,10 @@ vpath %.java src | ||
| 42 | 43 | ||
| 43 | 44 | ||
| 44 | buildfile: | 45 | buildfile: |
| 45 | - $(JAVAC) -cp lib/sherpaonnx.jar -d $(BUILD_DIR) -encoding UTF-8 src/$(EXAMPLE_FILE) | 46 | + $(JAVAC) -cp lib/sherpaonnx.jar -d $(BUILD_DIR) -encoding UTF-8 src/$(EXAMPLE_FILE) |
| 46 | 47 | ||
| 47 | buildmic: | 48 | buildmic: |
| 48 | - $(JAVAC) -cp lib/sherpaonnx.jar -d $(BUILD_DIR) -encoding UTF-8 src/$(EXAMPLE_Mic) | 49 | + $(JAVAC) -cp lib/sherpaonnx.jar -d $(BUILD_DIR) -encoding UTF-8 src/$(EXAMPLE_Mic) |
| 49 | 50 | ||
| 50 | rebuild: clean all | 51 | rebuild: clean all |
| 51 | 52 | ||
| @@ -63,8 +64,8 @@ clean: | @@ -63,8 +64,8 @@ clean: | ||
| 63 | mkdir -p $(BUILD_DIR) | 64 | mkdir -p $(BUILD_DIR) |
| 64 | mkdir -p ./lib | 65 | mkdir -p ./lib |
| 65 | 66 | ||
| 66 | -runfile: | ||
| 67 | - java -cp ./lib/sherpaonnx.jar:build $(RUNJFLAGS) DecodeFile test.wav | 67 | +runfile: packjar buildfile |
| 68 | + java -cp ./lib/sherpaonnx.jar:build $(RUNJFLAGS) DecodeFile test.wav | ||
| 68 | 69 | ||
| 69 | runhotwords: | 70 | runhotwords: |
| 70 | java -cp ./lib/sherpaonnx.jar:build $(RUNJFLAGS) DecodeFile hotwords.wav | 71 | java -cp ./lib/sherpaonnx.jar:build $(RUNJFLAGS) DecodeFile hotwords.wav |
| @@ -85,8 +86,7 @@ buildlib: $(LIB_FILES:.java=.class) | @@ -85,8 +86,7 @@ buildlib: $(LIB_FILES:.java=.class) | ||
| 85 | 86 | ||
| 86 | 87 | ||
| 87 | %.class: %.java | 88 | %.class: %.java |
| 88 | - | ||
| 89 | - $(JAVAC) -cp $(BUILD_DIR) -d $(BUILD_DIR) -encoding UTF-8 $< | 89 | + $(JAVAC) -cp $(BUILD_DIR) -d $(BUILD_DIR) -encoding UTF-8 $< |
| 90 | 90 | ||
| 91 | buildwebsocket: $(WEBSOCKET_FILES:.java=.class) | 91 | buildwebsocket: $(WEBSOCKET_FILES:.java=.class) |
| 92 | 92 | ||
| @@ -95,7 +95,7 @@ buildwebsocket: $(WEBSOCKET_FILES:.java=.class) | @@ -95,7 +95,7 @@ buildwebsocket: $(WEBSOCKET_FILES:.java=.class) | ||
| 95 | 95 | ||
| 96 | $(JAVAC) -cp $(BUILD_DIR):lib/slf4j-simple-1.7.25.jar:lib/slf4j-api-1.7.25.jar:lib/Java-WebSocket-1.5.3.jar:../lib/sherpaonnx.jar -d $(BUILD_DIR) -encoding UTF-8 $< | 96 | $(JAVAC) -cp $(BUILD_DIR):lib/slf4j-simple-1.7.25.jar:lib/slf4j-api-1.7.25.jar:lib/Java-WebSocket-1.5.3.jar:../lib/sherpaonnx.jar -d $(BUILD_DIR) -encoding UTF-8 $< |
| 97 | 97 | ||
| 98 | -packjar: | ||
| 99 | - jar cvfe lib/sherpaonnx.jar . -C $(BUILD_DIR) . | 98 | +packjar: buildlib |
| 99 | + jar cvfe lib/sherpaonnx.jar . -C $(BUILD_DIR) . | ||
| 100 | 100 | ||
| 101 | all: clean buildlib packjar buildfile buildmic downjar buildwebsocket | 101 | all: clean buildlib packjar buildfile buildmic downjar buildwebsocket |
sherpa-onnx/java-api/.gitignore
0 → 100644
| @@ -5,25 +5,25 @@ | @@ -5,25 +5,25 @@ | ||
| 5 | package com.k2fsa.sherpa.onnx; | 5 | package com.k2fsa.sherpa.onnx; |
| 6 | 6 | ||
| 7 | public class EndpointConfig { | 7 | public class EndpointConfig { |
| 8 | - private final EndpointRule rule1; | ||
| 9 | - private final EndpointRule rule2; | ||
| 10 | - private final EndpointRule rule3; | 8 | + private final EndpointRule rule1; |
| 9 | + private final EndpointRule rule2; | ||
| 10 | + private final EndpointRule rule3; | ||
| 11 | 11 | ||
| 12 | - public EndpointConfig(EndpointRule rule1, EndpointRule rule2, EndpointRule rule3) { | ||
| 13 | - this.rule1 = rule1; | ||
| 14 | - this.rule2 = rule2; | ||
| 15 | - this.rule3 = rule3; | ||
| 16 | - } | 12 | + public EndpointConfig(EndpointRule rule1, EndpointRule rule2, EndpointRule rule3) { |
| 13 | + this.rule1 = rule1; | ||
| 14 | + this.rule2 = rule2; | ||
| 15 | + this.rule3 = rule3; | ||
| 16 | + } | ||
| 17 | 17 | ||
| 18 | - public EndpointRule getRule1() { | ||
| 19 | - return rule1; | ||
| 20 | - } | 18 | + public EndpointRule getRule1() { |
| 19 | + return rule1; | ||
| 20 | + } | ||
| 21 | 21 | ||
| 22 | - public EndpointRule getRule2() { | ||
| 23 | - return rule2; | ||
| 24 | - } | 22 | + public EndpointRule getRule2() { |
| 23 | + return rule2; | ||
| 24 | + } | ||
| 25 | 25 | ||
| 26 | - public EndpointRule getRule3() { | ||
| 27 | - return rule3; | ||
| 28 | - } | 26 | + public EndpointRule getRule3() { |
| 27 | + return rule3; | ||
| 28 | + } | ||
| 29 | } | 29 | } |
| @@ -5,26 +5,26 @@ | @@ -5,26 +5,26 @@ | ||
| 5 | package com.k2fsa.sherpa.onnx; | 5 | package com.k2fsa.sherpa.onnx; |
| 6 | 6 | ||
| 7 | public class EndpointRule { | 7 | public class EndpointRule { |
| 8 | - private final boolean mustContainNonSilence; | ||
| 9 | - private final float minTrailingSilence; | ||
| 10 | - private final float minUtteranceLength; | 8 | + private final boolean mustContainNonSilence; |
| 9 | + private final float minTrailingSilence; | ||
| 10 | + private final float minUtteranceLength; | ||
| 11 | 11 | ||
| 12 | - public EndpointRule( | ||
| 13 | - boolean mustContainNonSilence, float minTrailingSilence, float minUtteranceLength) { | ||
| 14 | - this.mustContainNonSilence = mustContainNonSilence; | ||
| 15 | - this.minTrailingSilence = minTrailingSilence; | ||
| 16 | - this.minUtteranceLength = minUtteranceLength; | ||
| 17 | - } | 12 | + public EndpointRule( |
| 13 | + boolean mustContainNonSilence, float minTrailingSilence, float minUtteranceLength) { | ||
| 14 | + this.mustContainNonSilence = mustContainNonSilence; | ||
| 15 | + this.minTrailingSilence = minTrailingSilence; | ||
| 16 | + this.minUtteranceLength = minUtteranceLength; | ||
| 17 | + } | ||
| 18 | 18 | ||
| 19 | - public float getMinTrailingSilence() { | ||
| 20 | - return minTrailingSilence; | ||
| 21 | - } | 19 | + public float getMinTrailingSilence() { |
| 20 | + return minTrailingSilence; | ||
| 21 | + } | ||
| 22 | 22 | ||
| 23 | - public float getMinUtteranceLength() { | ||
| 24 | - return minUtteranceLength; | ||
| 25 | - } | 23 | + public float getMinUtteranceLength() { |
| 24 | + return minUtteranceLength; | ||
| 25 | + } | ||
| 26 | 26 | ||
| 27 | - public boolean getMustContainNonSilence() { | ||
| 28 | - return mustContainNonSilence; | ||
| 29 | - } | 27 | + public boolean getMustContainNonSilence() { |
| 28 | + return mustContainNonSilence; | ||
| 29 | + } | ||
| 30 | } | 30 | } |
| @@ -5,19 +5,19 @@ | @@ -5,19 +5,19 @@ | ||
| 5 | package com.k2fsa.sherpa.onnx; | 5 | package com.k2fsa.sherpa.onnx; |
| 6 | 6 | ||
| 7 | public class FeatureConfig { | 7 | public class FeatureConfig { |
| 8 | - private final int sampleRate; | ||
| 9 | - private final int featureDim; | 8 | + private final int sampleRate; |
| 9 | + private final int featureDim; | ||
| 10 | 10 | ||
| 11 | - public FeatureConfig(int sampleRate, int featureDim) { | ||
| 12 | - this.sampleRate = sampleRate; | ||
| 13 | - this.featureDim = featureDim; | ||
| 14 | - } | 11 | + public FeatureConfig(int sampleRate, int featureDim) { |
| 12 | + this.sampleRate = sampleRate; | ||
| 13 | + this.featureDim = featureDim; | ||
| 14 | + } | ||
| 15 | 15 | ||
| 16 | - public int getSampleRate() { | ||
| 17 | - return sampleRate; | ||
| 18 | - } | 16 | + public int getSampleRate() { |
| 17 | + return sampleRate; | ||
| 18 | + } | ||
| 19 | 19 | ||
| 20 | - public int getFeatureDim() { | ||
| 21 | - return featureDim; | ||
| 22 | - } | 20 | + public int getFeatureDim() { |
| 21 | + return featureDim; | ||
| 22 | + } | ||
| 23 | } | 23 | } |
| @@ -5,19 +5,19 @@ | @@ -5,19 +5,19 @@ | ||
| 5 | package com.k2fsa.sherpa.onnx; | 5 | package com.k2fsa.sherpa.onnx; |
| 6 | 6 | ||
| 7 | public class OnlineLMConfig { | 7 | public class OnlineLMConfig { |
| 8 | - private final String model; | ||
| 9 | - private final float scale; | 8 | + private final String model; |
| 9 | + private final float scale; | ||
| 10 | 10 | ||
| 11 | - public OnlineLMConfig(String model, float scale) { | ||
| 12 | - this.model = model; | ||
| 13 | - this.scale = scale; | ||
| 14 | - } | 11 | + public OnlineLMConfig(String model, float scale) { |
| 12 | + this.model = model; | ||
| 13 | + this.scale = scale; | ||
| 14 | + } | ||
| 15 | 15 | ||
| 16 | - public String getModel() { | ||
| 17 | - return model; | ||
| 18 | - } | 16 | + public String getModel() { |
| 17 | + return model; | ||
| 18 | + } | ||
| 19 | 19 | ||
| 20 | - public float getScale() { | ||
| 21 | - return scale; | ||
| 22 | - } | 20 | + public float getScale() { |
| 21 | + return scale; | ||
| 22 | + } | ||
| 23 | } | 23 | } |
| @@ -5,47 +5,51 @@ | @@ -5,47 +5,51 @@ | ||
| 5 | package com.k2fsa.sherpa.onnx; | 5 | package com.k2fsa.sherpa.onnx; |
| 6 | 6 | ||
| 7 | public class OnlineModelConfig { | 7 | public class OnlineModelConfig { |
| 8 | - private final OnlineParaformerModelConfig paraformer; | ||
| 9 | - private final OnlineTransducerModelConfig transducer; | ||
| 10 | - private final String tokens; | ||
| 11 | - private final int numThreads; | ||
| 12 | - private final boolean debug; | ||
| 13 | - private final String provider = "cpu"; | ||
| 14 | - private String modelType = ""; | ||
| 15 | - | ||
| 16 | - public OnlineModelConfig( | ||
| 17 | - String tokens, | ||
| 18 | - int numThreads, | ||
| 19 | - boolean debug, | ||
| 20 | - String modelType, | ||
| 21 | - OnlineParaformerModelConfig paraformer, | ||
| 22 | - OnlineTransducerModelConfig transducer) { | ||
| 23 | - | ||
| 24 | - this.tokens = tokens; | ||
| 25 | - this.numThreads = numThreads; | ||
| 26 | - this.debug = debug; | ||
| 27 | - this.modelType = modelType; | ||
| 28 | - this.paraformer = paraformer; | ||
| 29 | - this.transducer = transducer; | ||
| 30 | - } | ||
| 31 | - | ||
| 32 | - public OnlineParaformerModelConfig getParaformer() { | ||
| 33 | - return paraformer; | ||
| 34 | - } | ||
| 35 | - | ||
| 36 | - public OnlineTransducerModelConfig getTransducer() { | ||
| 37 | - return transducer; | ||
| 38 | - } | ||
| 39 | - | ||
| 40 | - public String getTokens() { | ||
| 41 | - return tokens; | ||
| 42 | - } | ||
| 43 | - | ||
| 44 | - public int getNumThreads() { | ||
| 45 | - return numThreads; | ||
| 46 | - } | ||
| 47 | - | ||
| 48 | - public boolean getDebug() { | ||
| 49 | - return debug; | ||
| 50 | - } | 8 | + private final OnlineParaformerModelConfig paraformer; |
| 9 | + private final OnlineTransducerModelConfig transducer; | ||
| 10 | + private final OnlineZipformer2CtcModelConfig zipformer2Ctc; | ||
| 11 | + private final String tokens; | ||
| 12 | + private final int numThreads; | ||
| 13 | + private final boolean debug; | ||
| 14 | + private final String provider = "cpu"; | ||
| 15 | + private String modelType = ""; | ||
| 16 | + | ||
| 17 | + public OnlineModelConfig( | ||
| 18 | + String tokens, | ||
| 19 | + int numThreads, | ||
| 20 | + boolean debug, | ||
| 21 | + String modelType, | ||
| 22 | + OnlineParaformerModelConfig paraformer, | ||
| 23 | + OnlineTransducerModelConfig transducer, | ||
| 24 | + OnlineZipformer2CtcModelConfig zipformer2Ctc | ||
| 25 | + ) { | ||
| 26 | + | ||
| 27 | + this.tokens = tokens; | ||
| 28 | + this.numThreads = numThreads; | ||
| 29 | + this.debug = debug; | ||
| 30 | + this.modelType = modelType; | ||
| 31 | + this.paraformer = paraformer; | ||
| 32 | + this.transducer = transducer; | ||
| 33 | + this.zipformer2Ctc = zipformer2Ctc; | ||
| 34 | + } | ||
| 35 | + | ||
| 36 | + public OnlineParaformerModelConfig getParaformer() { | ||
| 37 | + return paraformer; | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + public OnlineTransducerModelConfig getTransducer() { | ||
| 41 | + return transducer; | ||
| 42 | + } | ||
| 43 | + | ||
| 44 | + public String getTokens() { | ||
| 45 | + return tokens; | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + public int getNumThreads() { | ||
| 49 | + return numThreads; | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + public boolean getDebug() { | ||
| 53 | + return debug; | ||
| 54 | + } | ||
| 51 | } | 55 | } |
| @@ -5,19 +5,19 @@ | @@ -5,19 +5,19 @@ | ||
| 5 | package com.k2fsa.sherpa.onnx; | 5 | package com.k2fsa.sherpa.onnx; |
| 6 | 6 | ||
| 7 | public class OnlineParaformerModelConfig { | 7 | public class OnlineParaformerModelConfig { |
| 8 | - private final String encoder; | ||
| 9 | - private final String decoder; | 8 | + private final String encoder; |
| 9 | + private final String decoder; | ||
| 10 | 10 | ||
| 11 | - public OnlineParaformerModelConfig(String encoder, String decoder) { | ||
| 12 | - this.encoder = encoder; | ||
| 13 | - this.decoder = decoder; | ||
| 14 | - } | 11 | + public OnlineParaformerModelConfig(String encoder, String decoder) { |
| 12 | + this.encoder = encoder; | ||
| 13 | + this.decoder = decoder; | ||
| 14 | + } | ||
| 15 | 15 | ||
| 16 | - public String getEncoder() { | ||
| 17 | - return encoder; | ||
| 18 | - } | 16 | + public String getEncoder() { |
| 17 | + return encoder; | ||
| 18 | + } | ||
| 19 | 19 | ||
| 20 | - public String getDecoder() { | ||
| 21 | - return decoder; | ||
| 22 | - } | 20 | + public String getDecoder() { |
| 21 | + return decoder; | ||
| 22 | + } | ||
| 23 | } | 23 | } |
| @@ -32,336 +32,345 @@ usage example: | @@ -32,336 +32,345 @@ usage example: | ||
| 32 | */ | 32 | */ |
| 33 | package com.k2fsa.sherpa.onnx; | 33 | package com.k2fsa.sherpa.onnx; |
| 34 | 34 | ||
| 35 | -import java.io.*; | ||
| 36 | -import java.util.*; | 35 | +import java.io.BufferedInputStream; |
| 36 | +import java.io.File; | ||
| 37 | +import java.io.FileInputStream; | ||
| 38 | +import java.io.InputStream; | ||
| 39 | +import java.util.Enumeration; | ||
| 40 | +import java.util.HashMap; | ||
| 41 | +import java.util.Map; | ||
| 42 | +import java.util.Properties; | ||
| 37 | 43 | ||
| 38 | public class OnlineRecognizer { | 44 | public class OnlineRecognizer { |
| 39 | - private long ptr = 0; // this is the asr engine ptrss | ||
| 40 | - | ||
| 41 | - private int sampleRate = 16000; | ||
| 42 | - | ||
| 43 | - // load config file for OnlineRecognizer | ||
| 44 | - public OnlineRecognizer(String modelCfgPath) { | ||
| 45 | - Map<String, String> proMap = this.readProperties(modelCfgPath); | ||
| 46 | - try { | ||
| 47 | - int sampleRate = Integer.parseInt(proMap.getOrDefault("sample_rate", "16000").trim()); | ||
| 48 | - this.sampleRate = sampleRate; | ||
| 49 | - EndpointRule rule1 = | ||
| 50 | - new EndpointRule( | ||
| 51 | - false, | ||
| 52 | - Float.parseFloat(proMap.getOrDefault("rule1_min_trailing_silence", "2.4").trim()), | ||
| 53 | - 0.0F); | ||
| 54 | - EndpointRule rule2 = | ||
| 55 | - new EndpointRule( | ||
| 56 | - true, | ||
| 57 | - Float.parseFloat(proMap.getOrDefault("rule2_min_trailing_silence", "1.2").trim()), | ||
| 58 | - 0.0F); | ||
| 59 | - EndpointRule rule3 = | ||
| 60 | - new EndpointRule( | ||
| 61 | - false, | ||
| 62 | - 0.0F, | ||
| 63 | - Float.parseFloat(proMap.getOrDefault("rule3_min_utterance_length", "20").trim())); | ||
| 64 | - EndpointConfig endCfg = new EndpointConfig(rule1, rule2, rule3); | ||
| 65 | - | ||
| 66 | - OnlineParaformerModelConfig modelParaCfg = | ||
| 67 | - new OnlineParaformerModelConfig( | ||
| 68 | - proMap.getOrDefault("encoder", "").trim(), proMap.getOrDefault("decoder", "").trim()); | ||
| 69 | - OnlineTransducerModelConfig modelTranCfg = | ||
| 70 | - new OnlineTransducerModelConfig( | ||
| 71 | - proMap.getOrDefault("encoder", "").trim(), | ||
| 72 | - proMap.getOrDefault("decoder", "").trim(), | ||
| 73 | - proMap.getOrDefault("joiner", "").trim()); | ||
| 74 | - OnlineModelConfig modelCfg = | ||
| 75 | - new OnlineModelConfig( | ||
| 76 | - proMap.getOrDefault("tokens", "").trim(), | ||
| 77 | - Integer.parseInt(proMap.getOrDefault("num_threads", "4").trim()), | ||
| 78 | - false, | ||
| 79 | - proMap.getOrDefault("model_type", "zipformer").trim(), | ||
| 80 | - modelParaCfg, | ||
| 81 | - modelTranCfg); | ||
| 82 | - FeatureConfig featConfig = | ||
| 83 | - new FeatureConfig( | ||
| 84 | - sampleRate, Integer.parseInt(proMap.getOrDefault("feature_dim", "80").trim())); | ||
| 85 | - OnlineLMConfig onlineLmConfig = | ||
| 86 | - new OnlineLMConfig( | ||
| 87 | - proMap.getOrDefault("lm_model", "").trim(), | ||
| 88 | - Float.parseFloat(proMap.getOrDefault("lm_scale", "0.5").trim())); | ||
| 89 | - | ||
| 90 | - OnlineRecognizerConfig rcgCfg = | ||
| 91 | - new OnlineRecognizerConfig( | ||
| 92 | - featConfig, | ||
| 93 | - modelCfg, | ||
| 94 | - endCfg, | ||
| 95 | - onlineLmConfig, | ||
| 96 | - Boolean.parseBoolean(proMap.getOrDefault("enable_endpoint_detection", "true").trim()), | ||
| 97 | - proMap.getOrDefault("decoding_method", "modified_beam_search").trim(), | ||
| 98 | - Integer.parseInt(proMap.getOrDefault("max_active_paths", "4").trim()), | ||
| 99 | - proMap.getOrDefault("hotwords_file", "").trim(), | ||
| 100 | - Float.parseFloat(proMap.getOrDefault("hotwords_score", "1.5").trim())); | ||
| 101 | - // create a new Recognizer, first parameter kept for android asset_manager ANDROID_API__ >= 9 | ||
| 102 | - this.ptr = createOnlineRecognizer(new Object(), rcgCfg); | ||
| 103 | - | ||
| 104 | - } catch (Exception e) { | ||
| 105 | - System.err.println(e); | 45 | + private long ptr = 0; // this is the asr engine ptrss |
| 46 | + | ||
| 47 | + private int sampleRate = 16000; | ||
| 48 | + | ||
| 49 | + // load config file for OnlineRecognizer | ||
| 50 | + public OnlineRecognizer(String modelCfgPath) { | ||
| 51 | + Map<String, String> proMap = this.readProperties(modelCfgPath); | ||
| 52 | + try { | ||
| 53 | + int sampleRate = Integer.parseInt(proMap.getOrDefault("sample_rate", "16000").trim()); | ||
| 54 | + this.sampleRate = sampleRate; | ||
| 55 | + EndpointRule rule1 = | ||
| 56 | + new EndpointRule( | ||
| 57 | + false, | ||
| 58 | + Float.parseFloat(proMap.getOrDefault("rule1_min_trailing_silence", "2.4").trim()), | ||
| 59 | + 0.0F); | ||
| 60 | + EndpointRule rule2 = | ||
| 61 | + new EndpointRule( | ||
| 62 | + true, | ||
| 63 | + Float.parseFloat(proMap.getOrDefault("rule2_min_trailing_silence", "1.2").trim()), | ||
| 64 | + 0.0F); | ||
| 65 | + EndpointRule rule3 = | ||
| 66 | + new EndpointRule( | ||
| 67 | + false, | ||
| 68 | + 0.0F, | ||
| 69 | + Float.parseFloat(proMap.getOrDefault("rule3_min_utterance_length", "20").trim())); | ||
| 70 | + EndpointConfig endCfg = new EndpointConfig(rule1, rule2, rule3); | ||
| 71 | + | ||
| 72 | + OnlineParaformerModelConfig modelParaCfg = | ||
| 73 | + new OnlineParaformerModelConfig( | ||
| 74 | + proMap.getOrDefault("encoder", "").trim(), proMap.getOrDefault("decoder", "").trim()); | ||
| 75 | + OnlineTransducerModelConfig modelTranCfg = | ||
| 76 | + new OnlineTransducerModelConfig( | ||
| 77 | + proMap.getOrDefault("encoder", "").trim(), | ||
| 78 | + proMap.getOrDefault("decoder", "").trim(), | ||
| 79 | + proMap.getOrDefault("joiner", "").trim()); | ||
| 80 | + OnlineZipformer2CtcModelConfig zipformer2CtcConfig = new OnlineZipformer2CtcModelConfig(""); | ||
| 81 | + OnlineModelConfig modelCfg = | ||
| 82 | + new OnlineModelConfig( | ||
| 83 | + proMap.getOrDefault("tokens", "").trim(), | ||
| 84 | + Integer.parseInt(proMap.getOrDefault("num_threads", "4").trim()), | ||
| 85 | + false, | ||
| 86 | + proMap.getOrDefault("model_type", "zipformer").trim(), | ||
| 87 | + modelParaCfg, | ||
| 88 | + modelTranCfg, zipformer2CtcConfig); | ||
| 89 | + FeatureConfig featConfig = | ||
| 90 | + new FeatureConfig( | ||
| 91 | + sampleRate, Integer.parseInt(proMap.getOrDefault("feature_dim", "80").trim())); | ||
| 92 | + OnlineLMConfig onlineLmConfig = | ||
| 93 | + new OnlineLMConfig( | ||
| 94 | + proMap.getOrDefault("lm_model", "").trim(), | ||
| 95 | + Float.parseFloat(proMap.getOrDefault("lm_scale", "0.5").trim())); | ||
| 96 | + | ||
| 97 | + OnlineRecognizerConfig rcgCfg = | ||
| 98 | + new OnlineRecognizerConfig( | ||
| 99 | + featConfig, | ||
| 100 | + modelCfg, | ||
| 101 | + endCfg, | ||
| 102 | + onlineLmConfig, | ||
| 103 | + Boolean.parseBoolean(proMap.getOrDefault("enable_endpoint_detection", "true").trim()), | ||
| 104 | + proMap.getOrDefault("decoding_method", "modified_beam_search").trim(), | ||
| 105 | + Integer.parseInt(proMap.getOrDefault("max_active_paths", "4").trim()), | ||
| 106 | + proMap.getOrDefault("hotwords_file", "").trim(), | ||
| 107 | + Float.parseFloat(proMap.getOrDefault("hotwords_score", "1.5").trim())); | ||
| 108 | + // create a new Recognizer, first parameter kept for android asset_manager ANDROID_API__ >= 9 | ||
| 109 | + this.ptr = createOnlineRecognizer(new Object(), rcgCfg); | ||
| 110 | + | ||
| 111 | + } catch (Exception e) { | ||
| 112 | + System.err.println(e); | ||
| 113 | + } | ||
| 106 | } | 114 | } |
| 107 | - } | ||
| 108 | - | ||
| 109 | - // use for android asset_manager ANDROID_API__ >= 9 | ||
| 110 | - public OnlineRecognizer(Object assetManager, String modelCfgPath) { | ||
| 111 | - Map<String, String> proMap = this.readProperties(modelCfgPath); | ||
| 112 | - try { | ||
| 113 | - int sampleRate = Integer.parseInt(proMap.getOrDefault("sample_rate", "16000").trim()); | ||
| 114 | - this.sampleRate = sampleRate; | ||
| 115 | - EndpointRule rule1 = | ||
| 116 | - new EndpointRule( | ||
| 117 | - false, | ||
| 118 | - Float.parseFloat(proMap.getOrDefault("rule1_min_trailing_silence", "2.4").trim()), | ||
| 119 | - 0.0F); | ||
| 120 | - EndpointRule rule2 = | ||
| 121 | - new EndpointRule( | ||
| 122 | - true, | ||
| 123 | - Float.parseFloat(proMap.getOrDefault("rule2_min_trailing_silence", "1.2").trim()), | ||
| 124 | - 0.0F); | ||
| 125 | - EndpointRule rule3 = | ||
| 126 | - new EndpointRule( | ||
| 127 | - false, | ||
| 128 | - 0.0F, | ||
| 129 | - Float.parseFloat(proMap.getOrDefault("rule3_min_utterance_length", "20").trim())); | ||
| 130 | - EndpointConfig endCfg = new EndpointConfig(rule1, rule2, rule3); | ||
| 131 | - OnlineParaformerModelConfig modelParaCfg = | ||
| 132 | - new OnlineParaformerModelConfig( | ||
| 133 | - proMap.getOrDefault("encoder", "").trim(), proMap.getOrDefault("decoder", "").trim()); | ||
| 134 | - OnlineTransducerModelConfig modelTranCfg = | ||
| 135 | - new OnlineTransducerModelConfig( | ||
| 136 | - proMap.getOrDefault("encoder", "").trim(), | ||
| 137 | - proMap.getOrDefault("decoder", "").trim(), | ||
| 138 | - proMap.getOrDefault("joiner", "").trim()); | ||
| 139 | - | ||
| 140 | - OnlineModelConfig modelCfg = | ||
| 141 | - new OnlineModelConfig( | ||
| 142 | - proMap.getOrDefault("tokens", "").trim(), | ||
| 143 | - Integer.parseInt(proMap.getOrDefault("num_threads", "4").trim()), | ||
| 144 | - false, | ||
| 145 | - proMap.getOrDefault("model_type", "zipformer").trim(), | ||
| 146 | - modelParaCfg, | ||
| 147 | - modelTranCfg); | ||
| 148 | - FeatureConfig featConfig = | ||
| 149 | - new FeatureConfig( | ||
| 150 | - sampleRate, Integer.parseInt(proMap.getOrDefault("feature_dim", "80").trim())); | ||
| 151 | - | ||
| 152 | - OnlineLMConfig onlineLmConfig = | ||
| 153 | - new OnlineLMConfig( | ||
| 154 | - proMap.getOrDefault("lm_model", "").trim(), | ||
| 155 | - Float.parseFloat(proMap.getOrDefault("lm_scale", "0.5").trim())); | ||
| 156 | - | ||
| 157 | - OnlineRecognizerConfig rcgCfg = | ||
| 158 | - new OnlineRecognizerConfig( | ||
| 159 | - featConfig, | ||
| 160 | - modelCfg, | ||
| 161 | - endCfg, | ||
| 162 | - onlineLmConfig, | ||
| 163 | - Boolean.parseBoolean(proMap.getOrDefault("enable_endpoint_detection", "true").trim()), | ||
| 164 | - proMap.getOrDefault("decoding_method", "modified_beam_search").trim(), | ||
| 165 | - Integer.parseInt(proMap.getOrDefault("max_active_paths", "4").trim()), | ||
| 166 | - proMap.getOrDefault("hotwords_file", "").trim(), | ||
| 167 | - Float.parseFloat(proMap.getOrDefault("hotwords_score", "1.5").trim())); | ||
| 168 | - // create a new Recognizer, first parameter kept for android asset_manager ANDROID_API__ >= 9 | ||
| 169 | - this.ptr = createOnlineRecognizer(assetManager, rcgCfg); | ||
| 170 | - | ||
| 171 | - } catch (Exception e) { | ||
| 172 | - System.err.println(e); | 115 | + |
| 116 | + // use for android asset_manager ANDROID_API__ >= 9 | ||
| 117 | + public OnlineRecognizer(Object assetManager, String modelCfgPath) { | ||
| 118 | + Map<String, String> proMap = this.readProperties(modelCfgPath); | ||
| 119 | + try { | ||
| 120 | + int sampleRate = Integer.parseInt(proMap.getOrDefault("sample_rate", "16000").trim()); | ||
| 121 | + this.sampleRate = sampleRate; | ||
| 122 | + EndpointRule rule1 = | ||
| 123 | + new EndpointRule( | ||
| 124 | + false, | ||
| 125 | + Float.parseFloat(proMap.getOrDefault("rule1_min_trailing_silence", "2.4").trim()), | ||
| 126 | + 0.0F); | ||
| 127 | + EndpointRule rule2 = | ||
| 128 | + new EndpointRule( | ||
| 129 | + true, | ||
| 130 | + Float.parseFloat(proMap.getOrDefault("rule2_min_trailing_silence", "1.2").trim()), | ||
| 131 | + 0.0F); | ||
| 132 | + EndpointRule rule3 = | ||
| 133 | + new EndpointRule( | ||
| 134 | + false, | ||
| 135 | + 0.0F, | ||
| 136 | + Float.parseFloat(proMap.getOrDefault("rule3_min_utterance_length", "20").trim())); | ||
| 137 | + EndpointConfig endCfg = new EndpointConfig(rule1, rule2, rule3); | ||
| 138 | + OnlineParaformerModelConfig modelParaCfg = | ||
| 139 | + new OnlineParaformerModelConfig( | ||
| 140 | + proMap.getOrDefault("encoder", "").trim(), proMap.getOrDefault("decoder", "").trim()); | ||
| 141 | + OnlineTransducerModelConfig modelTranCfg = | ||
| 142 | + new OnlineTransducerModelConfig( | ||
| 143 | + proMap.getOrDefault("encoder", "").trim(), | ||
| 144 | + proMap.getOrDefault("decoder", "").trim(), | ||
| 145 | + proMap.getOrDefault("joiner", "").trim()); | ||
| 146 | + OnlineZipformer2CtcModelConfig zipformer2CtcConfig = new OnlineZipformer2CtcModelConfig(""); | ||
| 147 | + | ||
| 148 | + OnlineModelConfig modelCfg = | ||
| 149 | + new OnlineModelConfig( | ||
| 150 | + proMap.getOrDefault("tokens", "").trim(), | ||
| 151 | + Integer.parseInt(proMap.getOrDefault("num_threads", "4").trim()), | ||
| 152 | + false, | ||
| 153 | + proMap.getOrDefault("model_type", "zipformer").trim(), | ||
| 154 | + modelParaCfg, | ||
| 155 | + modelTranCfg, zipformer2CtcConfig); | ||
| 156 | + FeatureConfig featConfig = | ||
| 157 | + new FeatureConfig( | ||
| 158 | + sampleRate, Integer.parseInt(proMap.getOrDefault("feature_dim", "80").trim())); | ||
| 159 | + | ||
| 160 | + OnlineLMConfig onlineLmConfig = | ||
| 161 | + new OnlineLMConfig( | ||
| 162 | + proMap.getOrDefault("lm_model", "").trim(), | ||
| 163 | + Float.parseFloat(proMap.getOrDefault("lm_scale", "0.5").trim())); | ||
| 164 | + | ||
| 165 | + OnlineRecognizerConfig rcgCfg = | ||
| 166 | + new OnlineRecognizerConfig( | ||
| 167 | + featConfig, | ||
| 168 | + modelCfg, | ||
| 169 | + endCfg, | ||
| 170 | + onlineLmConfig, | ||
| 171 | + Boolean.parseBoolean(proMap.getOrDefault("enable_endpoint_detection", "true").trim()), | ||
| 172 | + proMap.getOrDefault("decoding_method", "modified_beam_search").trim(), | ||
| 173 | + Integer.parseInt(proMap.getOrDefault("max_active_paths", "4").trim()), | ||
| 174 | + proMap.getOrDefault("hotwords_file", "").trim(), | ||
| 175 | + Float.parseFloat(proMap.getOrDefault("hotwords_score", "1.5").trim())); | ||
| 176 | + // create a new Recognizer, first parameter kept for android asset_manager ANDROID_API__ >= 9 | ||
| 177 | + this.ptr = createOnlineRecognizer(assetManager, rcgCfg); | ||
| 178 | + | ||
| 179 | + } catch (Exception e) { | ||
| 180 | + System.err.println(e); | ||
| 181 | + } | ||
| 173 | } | 182 | } |
| 174 | - } | ||
| 175 | - | ||
| 176 | - // set onlineRecognizer by parameter | ||
| 177 | - public OnlineRecognizer( | ||
| 178 | - String tokens, | ||
| 179 | - String encoder, | ||
| 180 | - String decoder, | ||
| 181 | - String joiner, | ||
| 182 | - int numThreads, | ||
| 183 | - int sampleRate, | ||
| 184 | - int featureDim, | ||
| 185 | - boolean enableEndpointDetection, | ||
| 186 | - float rule1MinTrailingSilence, | ||
| 187 | - float rule2MinTrailingSilence, | ||
| 188 | - float rule3MinUtteranceLength, | ||
| 189 | - String decodingMethod, | ||
| 190 | - String lm_model, | ||
| 191 | - float lm_scale, | ||
| 192 | - int maxActivePaths, | ||
| 193 | - String hotwordsFile, | ||
| 194 | - float hotwordsScore, | ||
| 195 | - String modelType) { | ||
| 196 | - this.sampleRate = sampleRate; | ||
| 197 | - EndpointRule rule1 = new EndpointRule(false, rule1MinTrailingSilence, 0.0F); | ||
| 198 | - EndpointRule rule2 = new EndpointRule(true, rule2MinTrailingSilence, 0.0F); | ||
| 199 | - EndpointRule rule3 = new EndpointRule(false, 0.0F, rule3MinUtteranceLength); | ||
| 200 | - EndpointConfig endCfg = new EndpointConfig(rule1, rule2, rule3); | ||
| 201 | - OnlineParaformerModelConfig modelParaCfg = new OnlineParaformerModelConfig(encoder, decoder); | ||
| 202 | - OnlineTransducerModelConfig modelTranCfg = | ||
| 203 | - new OnlineTransducerModelConfig(encoder, decoder, joiner); | ||
| 204 | - OnlineModelConfig modelCfg = | ||
| 205 | - new OnlineModelConfig(tokens, numThreads, false, modelType, modelParaCfg, modelTranCfg); | ||
| 206 | - FeatureConfig featConfig = new FeatureConfig(sampleRate, featureDim); | ||
| 207 | - OnlineLMConfig onlineLmConfig = new OnlineLMConfig(lm_model, lm_scale); | ||
| 208 | - OnlineRecognizerConfig rcgCfg = | ||
| 209 | - new OnlineRecognizerConfig( | ||
| 210 | - featConfig, | ||
| 211 | - modelCfg, | ||
| 212 | - endCfg, | ||
| 213 | - onlineLmConfig, | ||
| 214 | - enableEndpointDetection, | ||
| 215 | - decodingMethod, | ||
| 216 | - maxActivePaths, | ||
| 217 | - hotwordsFile, | ||
| 218 | - hotwordsScore); | ||
| 219 | - // create a new Recognizer, first parameter kept for android asset_manager ANDROID_API__ >= 9 | ||
| 220 | - this.ptr = createOnlineRecognizer(new Object(), rcgCfg); | ||
| 221 | - } | ||
| 222 | - | ||
| 223 | - private Map<String, String> readProperties(String modelCfgPath) { | ||
| 224 | - // read and parse config file | ||
| 225 | - Properties props = new Properties(); | ||
| 226 | - Map<String, String> proMap = new HashMap<>(); | ||
| 227 | - try { | ||
| 228 | - File file = new File(modelCfgPath); | ||
| 229 | - if (!file.exists()) { | ||
| 230 | - System.out.println("model cfg file not exists!"); | ||
| 231 | - System.exit(0); | ||
| 232 | - } | ||
| 233 | - InputStream in = new BufferedInputStream(new FileInputStream(modelCfgPath)); | ||
| 234 | - props.load(in); | ||
| 235 | - Enumeration en = props.propertyNames(); | ||
| 236 | - while (en.hasMoreElements()) { | ||
| 237 | - String key = (String) en.nextElement(); | ||
| 238 | - String Property = props.getProperty(key); | ||
| 239 | - proMap.put(key, Property); | ||
| 240 | - } | ||
| 241 | - | ||
| 242 | - } catch (Exception e) { | ||
| 243 | - e.printStackTrace(); | 183 | + |
| 184 | + // set onlineRecognizer by parameter | ||
| 185 | + public OnlineRecognizer( | ||
| 186 | + String tokens, | ||
| 187 | + String encoder, | ||
| 188 | + String decoder, | ||
| 189 | + String joiner, | ||
| 190 | + int numThreads, | ||
| 191 | + int sampleRate, | ||
| 192 | + int featureDim, | ||
| 193 | + boolean enableEndpointDetection, | ||
| 194 | + float rule1MinTrailingSilence, | ||
| 195 | + float rule2MinTrailingSilence, | ||
| 196 | + float rule3MinUtteranceLength, | ||
| 197 | + String decodingMethod, | ||
| 198 | + String lm_model, | ||
| 199 | + float lm_scale, | ||
| 200 | + int maxActivePaths, | ||
| 201 | + String hotwordsFile, | ||
| 202 | + float hotwordsScore, | ||
| 203 | + String modelType) { | ||
| 204 | + this.sampleRate = sampleRate; | ||
| 205 | + EndpointRule rule1 = new EndpointRule(false, rule1MinTrailingSilence, 0.0F); | ||
| 206 | + EndpointRule rule2 = new EndpointRule(true, rule2MinTrailingSilence, 0.0F); | ||
| 207 | + EndpointRule rule3 = new EndpointRule(false, 0.0F, rule3MinUtteranceLength); | ||
| 208 | + EndpointConfig endCfg = new EndpointConfig(rule1, rule2, rule3); | ||
| 209 | + OnlineParaformerModelConfig modelParaCfg = new OnlineParaformerModelConfig(encoder, decoder); | ||
| 210 | + OnlineTransducerModelConfig modelTranCfg = | ||
| 211 | + new OnlineTransducerModelConfig(encoder, decoder, joiner); | ||
| 212 | + OnlineZipformer2CtcModelConfig zipformer2CtcConfig = new OnlineZipformer2CtcModelConfig(""); | ||
| 213 | + OnlineModelConfig modelCfg = | ||
| 214 | + new OnlineModelConfig(tokens, numThreads, false, modelType, modelParaCfg, modelTranCfg, zipformer2CtcConfig); | ||
| 215 | + FeatureConfig featConfig = new FeatureConfig(sampleRate, featureDim); | ||
| 216 | + OnlineLMConfig onlineLmConfig = new OnlineLMConfig(lm_model, lm_scale); | ||
| 217 | + OnlineRecognizerConfig rcgCfg = | ||
| 218 | + new OnlineRecognizerConfig( | ||
| 219 | + featConfig, | ||
| 220 | + modelCfg, | ||
| 221 | + endCfg, | ||
| 222 | + onlineLmConfig, | ||
| 223 | + enableEndpointDetection, | ||
| 224 | + decodingMethod, | ||
| 225 | + maxActivePaths, | ||
| 226 | + hotwordsFile, | ||
| 227 | + hotwordsScore); | ||
| 228 | + // create a new Recognizer, first parameter kept for android asset_manager ANDROID_API__ >= 9 | ||
| 229 | + this.ptr = createOnlineRecognizer(new Object(), rcgCfg); | ||
| 244 | } | 230 | } |
| 245 | - return proMap; | ||
| 246 | - } | ||
| 247 | - | ||
| 248 | - public void decodeStream(OnlineStream s) throws Exception { | ||
| 249 | - if (this.ptr == 0) throw new Exception("null exception for recognizer ptr"); | ||
| 250 | - long streamPtr = s.getPtr(); | ||
| 251 | - if (streamPtr == 0) throw new Exception("null exception for stream ptr"); | ||
| 252 | - // when feeded samples to engine, call DecodeStream to let it process | ||
| 253 | - decodeStream(this.ptr, streamPtr); | ||
| 254 | - } | ||
| 255 | - | ||
| 256 | - public void decodeStreams(OnlineStream[] ssOjb) throws Exception { | ||
| 257 | - if (this.ptr == 0) throw new Exception("null exception for recognizer ptr"); | ||
| 258 | - // decode for multiple streams | ||
| 259 | - long[] ss = new long[ssOjb.length]; | ||
| 260 | - for (int i = 0; i < ssOjb.length; i++) { | ||
| 261 | - ss[i] = ssOjb[i].getPtr(); | ||
| 262 | - if (ss[i] == 0) throw new Exception("null exception for stream ptr"); | 231 | + |
| 232 | + public static float[] readWavFile(String fileName) { | ||
| 233 | + // read data from the filename | ||
| 234 | + Object[] wavdata = readWave(fileName); | ||
| 235 | + Object data = wavdata[0]; // data[0] is float data, data[1] sample rate | ||
| 236 | + | ||
| 237 | + float[] floatData = (float[]) data; | ||
| 238 | + | ||
| 239 | + return floatData; | ||
| 263 | } | 240 | } |
| 264 | - decodeStreams(this.ptr, ss); | ||
| 265 | - } | ||
| 266 | 241 | ||
| 267 | - public boolean isReady(OnlineStream s) throws Exception { | ||
| 268 | - // whether the engine is ready for decode | ||
| 269 | - if (this.ptr == 0) throw new Exception("null exception for recognizer ptr"); | ||
| 270 | - long streamPtr = s.getPtr(); | ||
| 271 | - if (streamPtr == 0) throw new Exception("null exception for stream ptr"); | ||
| 272 | - return isReady(this.ptr, streamPtr); | ||
| 273 | - } | 242 | + // load the libsherpa-onnx-jni.so lib |
| 243 | + public static void loadSoLib(String soPath) { | ||
| 244 | + // load libsherpa-onnx-jni.so lib from the path | ||
| 274 | 245 | ||
| 275 | - public String getResult(OnlineStream s) throws Exception { | ||
| 276 | - // get text from the engine | ||
| 277 | - if (this.ptr == 0) throw new Exception("null exception for recognizer ptr"); | ||
| 278 | - long streamPtr = s.getPtr(); | ||
| 279 | - if (streamPtr == 0) throw new Exception("null exception for stream ptr"); | ||
| 280 | - return getResult(this.ptr, streamPtr); | ||
| 281 | - } | 246 | + System.out.println("so lib path=" + soPath + "\n"); |
| 247 | + System.load(soPath.trim()); | ||
| 248 | + System.out.println("load so lib succeed\n"); | ||
| 249 | + } | ||
| 282 | 250 | ||
| 283 | - public boolean isEndpoint(OnlineStream s) throws Exception { | ||
| 284 | - if (this.ptr == 0) throw new Exception("null exception for recognizer ptr"); | ||
| 285 | - long streamPtr = s.getPtr(); | ||
| 286 | - if (streamPtr == 0) throw new Exception("null exception for stream ptr"); | ||
| 287 | - return isEndpoint(this.ptr, streamPtr); | ||
| 288 | - } | 251 | + public static void setSoPath(String soPath) { |
| 252 | + OnlineRecognizer.loadSoLib(soPath); | ||
| 253 | + OnlineStream.loadSoLib(soPath); | ||
| 254 | + } | ||
| 289 | 255 | ||
| 290 | - public void reSet(OnlineStream s) throws Exception { | ||
| 291 | - if (this.ptr == 0) throw new Exception("null exception for recognizer ptr"); | ||
| 292 | - long streamPtr = s.getPtr(); | ||
| 293 | - if (streamPtr == 0) throw new Exception("null exception for stream ptr"); | ||
| 294 | - reSet(this.ptr, streamPtr); | ||
| 295 | - } | 256 | + private static native Object[] readWave(String fileName); // static |
| 257 | + | ||
| 258 | + private Map<String, String> readProperties(String modelCfgPath) { | ||
| 259 | + // read and parse config file | ||
| 260 | + Properties props = new Properties(); | ||
| 261 | + Map<String, String> proMap = new HashMap<>(); | ||
| 262 | + try { | ||
| 263 | + File file = new File(modelCfgPath); | ||
| 264 | + if (!file.exists()) { | ||
| 265 | + System.out.println("model cfg file not exists!"); | ||
| 266 | + System.exit(0); | ||
| 267 | + } | ||
| 268 | + InputStream in = new BufferedInputStream(new FileInputStream(modelCfgPath)); | ||
| 269 | + props.load(in); | ||
| 270 | + Enumeration en = props.propertyNames(); | ||
| 271 | + while (en.hasMoreElements()) { | ||
| 272 | + String key = (String) en.nextElement(); | ||
| 273 | + String Property = props.getProperty(key); | ||
| 274 | + proMap.put(key, Property); | ||
| 275 | + } | ||
| 296 | 276 | ||
| 297 | - public OnlineStream createStream() throws Exception { | ||
| 298 | - // create one stream for data to feed in | ||
| 299 | - if (this.ptr == 0) throw new Exception("null exception for recognizer ptr"); | ||
| 300 | - long streamPtr = createStream(this.ptr); | ||
| 301 | - OnlineStream stream = new OnlineStream(streamPtr, this.sampleRate); | ||
| 302 | - return stream; | ||
| 303 | - } | 277 | + } catch (Exception e) { |
| 278 | + e.printStackTrace(); | ||
| 279 | + } | ||
| 280 | + return proMap; | ||
| 281 | + } | ||
| 304 | 282 | ||
| 305 | - public static float[] readWavFile(String fileName) { | ||
| 306 | - // read data from the filename | ||
| 307 | - Object[] wavdata = readWave(fileName); | ||
| 308 | - Object data = wavdata[0]; // data[0] is float data, data[1] sample rate | 283 | + public void decodeStream(OnlineStream s) throws Exception { |
| 284 | + if (this.ptr == 0) throw new Exception("null exception for recognizer ptr"); | ||
| 285 | + long streamPtr = s.getPtr(); | ||
| 286 | + if (streamPtr == 0) throw new Exception("null exception for stream ptr"); | ||
| 287 | + // when feeded samples to engine, call DecodeStream to let it process | ||
| 288 | + decodeStream(this.ptr, streamPtr); | ||
| 289 | + } | ||
| 309 | 290 | ||
| 310 | - float[] floatData = (float[]) data; | 291 | + public void decodeStreams(OnlineStream[] ssOjb) throws Exception { |
| 292 | + if (this.ptr == 0) throw new Exception("null exception for recognizer ptr"); | ||
| 293 | + // decode for multiple streams | ||
| 294 | + long[] ss = new long[ssOjb.length]; | ||
| 295 | + for (int i = 0; i < ssOjb.length; i++) { | ||
| 296 | + ss[i] = ssOjb[i].getPtr(); | ||
| 297 | + if (ss[i] == 0) throw new Exception("null exception for stream ptr"); | ||
| 298 | + } | ||
| 299 | + decodeStreams(this.ptr, ss); | ||
| 300 | + } | ||
| 311 | 301 | ||
| 312 | - return floatData; | ||
| 313 | - } | 302 | + public boolean isReady(OnlineStream s) throws Exception { |
| 303 | + // whether the engine is ready for decode | ||
| 304 | + if (this.ptr == 0) throw new Exception("null exception for recognizer ptr"); | ||
| 305 | + long streamPtr = s.getPtr(); | ||
| 306 | + if (streamPtr == 0) throw new Exception("null exception for stream ptr"); | ||
| 307 | + return isReady(this.ptr, streamPtr); | ||
| 308 | + } | ||
| 314 | 309 | ||
| 315 | - // load the libsherpa-onnx-jni.so lib | ||
| 316 | - public static void loadSoLib(String soPath) { | ||
| 317 | - // load libsherpa-onnx-jni.so lib from the path | 310 | + public String getResult(OnlineStream s) throws Exception { |
| 311 | + // get text from the engine | ||
| 312 | + if (this.ptr == 0) throw new Exception("null exception for recognizer ptr"); | ||
| 313 | + long streamPtr = s.getPtr(); | ||
| 314 | + if (streamPtr == 0) throw new Exception("null exception for stream ptr"); | ||
| 315 | + return getResult(this.ptr, streamPtr); | ||
| 316 | + } | ||
| 318 | 317 | ||
| 319 | - System.out.println("so lib path=" + soPath + "\n"); | ||
| 320 | - System.load(soPath.trim()); | ||
| 321 | - System.out.println("load so lib succeed\n"); | ||
| 322 | - } | 318 | + public boolean isEndpoint(OnlineStream s) throws Exception { |
| 319 | + if (this.ptr == 0) throw new Exception("null exception for recognizer ptr"); | ||
| 320 | + long streamPtr = s.getPtr(); | ||
| 321 | + if (streamPtr == 0) throw new Exception("null exception for stream ptr"); | ||
| 322 | + return isEndpoint(this.ptr, streamPtr); | ||
| 323 | + } | ||
| 323 | 324 | ||
| 324 | - public static void setSoPath(String soPath) { | ||
| 325 | - OnlineRecognizer.loadSoLib(soPath); | ||
| 326 | - OnlineStream.loadSoLib(soPath); | ||
| 327 | - } | 325 | + public void reSet(OnlineStream s) throws Exception { |
| 326 | + if (this.ptr == 0) throw new Exception("null exception for recognizer ptr"); | ||
| 327 | + long streamPtr = s.getPtr(); | ||
| 328 | + if (streamPtr == 0) throw new Exception("null exception for stream ptr"); | ||
| 329 | + reSet(this.ptr, streamPtr); | ||
| 330 | + } | ||
| 328 | 331 | ||
| 329 | - protected void finalize() throws Throwable { | ||
| 330 | - release(); | ||
| 331 | - } | 332 | + public OnlineStream createStream() throws Exception { |
| 333 | + // create one stream for data to feed in | ||
| 334 | + if (this.ptr == 0) throw new Exception("null exception for recognizer ptr"); | ||
| 335 | + long streamPtr = createStream(this.ptr); | ||
| 336 | + OnlineStream stream = new OnlineStream(streamPtr, this.sampleRate); | ||
| 337 | + return stream; | ||
| 338 | + } | ||
| 332 | 339 | ||
| 333 | - // recognizer release, you'd better call it manually if not use anymore | ||
| 334 | - public void release() { | ||
| 335 | - if (this.ptr == 0) return; | ||
| 336 | - deleteOnlineRecognizer(this.ptr); | ||
| 337 | - this.ptr = 0; | ||
| 338 | - } | 340 | + protected void finalize() throws Throwable { |
| 341 | + release(); | ||
| 342 | + } | ||
| 339 | 343 | ||
| 340 | - // stream release, you'd better call it manually if not use anymore | ||
| 341 | - public void releaseStream(OnlineStream s) { | ||
| 342 | - s.release(); | ||
| 343 | - } | 344 | + // recognizer release, you'd better call it manually if not use anymore |
| 345 | + public void release() { | ||
| 346 | + if (this.ptr == 0) return; | ||
| 347 | + deleteOnlineRecognizer(this.ptr); | ||
| 348 | + this.ptr = 0; | ||
| 349 | + } | ||
| 344 | 350 | ||
| 345 | - // JNI interface libsherpa-onnx-jni.so | 351 | + // JNI interface libsherpa-onnx-jni.so |
| 346 | 352 | ||
| 347 | - private static native Object[] readWave(String fileName); // static | 353 | + // stream release, you'd better call it manually if not use anymore |
| 354 | + public void releaseStream(OnlineStream s) { | ||
| 355 | + s.release(); | ||
| 356 | + } | ||
| 348 | 357 | ||
| 349 | - private native String getResult(long ptr, long streamPtr); | 358 | + private native String getResult(long ptr, long streamPtr); |
| 350 | 359 | ||
| 351 | - private native void decodeStream(long ptr, long streamPtr); | 360 | + private native void decodeStream(long ptr, long streamPtr); |
| 352 | 361 | ||
| 353 | - private native void decodeStreams(long ptr, long[] ssPtr); | 362 | + private native void decodeStreams(long ptr, long[] ssPtr); |
| 354 | 363 | ||
| 355 | - private native boolean isReady(long ptr, long streamPtr); | 364 | + private native boolean isReady(long ptr, long streamPtr); |
| 356 | 365 | ||
| 357 | - // first parameter keep for android asset_manager ANDROID_API__ >= 9 | ||
| 358 | - private native long createOnlineRecognizer(Object asset, OnlineRecognizerConfig config); | 366 | + // first parameter keep for android asset_manager ANDROID_API__ >= 9 |
| 367 | + private native long createOnlineRecognizer(Object asset, OnlineRecognizerConfig config); | ||
| 359 | 368 | ||
| 360 | - private native long createStream(long ptr); | 369 | + private native long createStream(long ptr); |
| 361 | 370 | ||
| 362 | - private native void deleteOnlineRecognizer(long ptr); | 371 | + private native void deleteOnlineRecognizer(long ptr); |
| 363 | 372 | ||
| 364 | - private native boolean isEndpoint(long ptr, long streamPtr); | 373 | + private native boolean isEndpoint(long ptr, long streamPtr); |
| 365 | 374 | ||
| 366 | - private native void reSet(long ptr, long streamPtr); | 375 | + private native void reSet(long ptr, long streamPtr); |
| 367 | } | 376 | } |
| @@ -5,62 +5,62 @@ | @@ -5,62 +5,62 @@ | ||
| 5 | package com.k2fsa.sherpa.onnx; | 5 | package com.k2fsa.sherpa.onnx; |
| 6 | 6 | ||
| 7 | public class OnlineRecognizerConfig { | 7 | public class OnlineRecognizerConfig { |
| 8 | - private final FeatureConfig featConfig; | ||
| 9 | - private final OnlineModelConfig modelConfig; | ||
| 10 | - private final EndpointConfig endpointConfig; | ||
| 11 | - private final OnlineLMConfig lmConfig; | ||
| 12 | - private final boolean enableEndpoint; | ||
| 13 | - private final String decodingMethod; | ||
| 14 | - private final int maxActivePaths; | ||
| 15 | - private final String hotwordsFile; | ||
| 16 | - private final float hotwordsScore; | 8 | + private final FeatureConfig featConfig; |
| 9 | + private final OnlineModelConfig modelConfig; | ||
| 10 | + private final EndpointConfig endpointConfig; | ||
| 11 | + private final OnlineLMConfig lmConfig; | ||
| 12 | + private final boolean enableEndpoint; | ||
| 13 | + private final String decodingMethod; | ||
| 14 | + private final int maxActivePaths; | ||
| 15 | + private final String hotwordsFile; | ||
| 16 | + private final float hotwordsScore; | ||
| 17 | 17 | ||
| 18 | - public OnlineRecognizerConfig( | ||
| 19 | - FeatureConfig featConfig, | ||
| 20 | - OnlineModelConfig modelConfig, | ||
| 21 | - EndpointConfig endpointConfig, | ||
| 22 | - OnlineLMConfig lmConfig, | ||
| 23 | - boolean enableEndpoint, | ||
| 24 | - String decodingMethod, | ||
| 25 | - int maxActivePaths, | ||
| 26 | - String hotwordsFile, | ||
| 27 | - float hotwordsScore) { | ||
| 28 | - this.featConfig = featConfig; | ||
| 29 | - this.modelConfig = modelConfig; | ||
| 30 | - this.endpointConfig = endpointConfig; | ||
| 31 | - this.lmConfig = lmConfig; | ||
| 32 | - this.enableEndpoint = enableEndpoint; | ||
| 33 | - this.decodingMethod = decodingMethod; | ||
| 34 | - this.maxActivePaths = maxActivePaths; | ||
| 35 | - this.hotwordsFile = hotwordsFile; | ||
| 36 | - this.hotwordsScore = hotwordsScore; | ||
| 37 | - } | 18 | + public OnlineRecognizerConfig( |
| 19 | + FeatureConfig featConfig, | ||
| 20 | + OnlineModelConfig modelConfig, | ||
| 21 | + EndpointConfig endpointConfig, | ||
| 22 | + OnlineLMConfig lmConfig, | ||
| 23 | + boolean enableEndpoint, | ||
| 24 | + String decodingMethod, | ||
| 25 | + int maxActivePaths, | ||
| 26 | + String hotwordsFile, | ||
| 27 | + float hotwordsScore) { | ||
| 28 | + this.featConfig = featConfig; | ||
| 29 | + this.modelConfig = modelConfig; | ||
| 30 | + this.endpointConfig = endpointConfig; | ||
| 31 | + this.lmConfig = lmConfig; | ||
| 32 | + this.enableEndpoint = enableEndpoint; | ||
| 33 | + this.decodingMethod = decodingMethod; | ||
| 34 | + this.maxActivePaths = maxActivePaths; | ||
| 35 | + this.hotwordsFile = hotwordsFile; | ||
| 36 | + this.hotwordsScore = hotwordsScore; | ||
| 37 | + } | ||
| 38 | 38 | ||
| 39 | - public OnlineLMConfig getLmConfig() { | ||
| 40 | - return lmConfig; | ||
| 41 | - } | 39 | + public OnlineLMConfig getLmConfig() { |
| 40 | + return lmConfig; | ||
| 41 | + } | ||
| 42 | 42 | ||
| 43 | - public FeatureConfig getFeatConfig() { | ||
| 44 | - return featConfig; | ||
| 45 | - } | 43 | + public FeatureConfig getFeatConfig() { |
| 44 | + return featConfig; | ||
| 45 | + } | ||
| 46 | 46 | ||
| 47 | - public OnlineModelConfig getModelConfig() { | ||
| 48 | - return modelConfig; | ||
| 49 | - } | 47 | + public OnlineModelConfig getModelConfig() { |
| 48 | + return modelConfig; | ||
| 49 | + } | ||
| 50 | 50 | ||
| 51 | - public EndpointConfig getEndpointConfig() { | ||
| 52 | - return endpointConfig; | ||
| 53 | - } | 51 | + public EndpointConfig getEndpointConfig() { |
| 52 | + return endpointConfig; | ||
| 53 | + } | ||
| 54 | 54 | ||
| 55 | - public boolean isEnableEndpoint() { | ||
| 56 | - return enableEndpoint; | ||
| 57 | - } | 55 | + public boolean isEnableEndpoint() { |
| 56 | + return enableEndpoint; | ||
| 57 | + } | ||
| 58 | 58 | ||
| 59 | - public String getDecodingMethod() { | ||
| 60 | - return decodingMethod; | ||
| 61 | - } | 59 | + public String getDecodingMethod() { |
| 60 | + return decodingMethod; | ||
| 61 | + } | ||
| 62 | 62 | ||
| 63 | - public int getMaxActivePaths() { | ||
| 64 | - return maxActivePaths; | ||
| 65 | - } | 63 | + public int getMaxActivePaths() { |
| 64 | + return maxActivePaths; | ||
| 65 | + } | ||
| 66 | } | 66 | } |
| @@ -4,83 +4,81 @@ | @@ -4,83 +4,81 @@ | ||
| 4 | // Stream is used for feeding data to the asr engine | 4 | // Stream is used for feeding data to the asr engine |
| 5 | package com.k2fsa.sherpa.onnx; | 5 | package com.k2fsa.sherpa.onnx; |
| 6 | 6 | ||
| 7 | -import java.io.*; | ||
| 8 | -import java.util.*; | ||
| 9 | - | ||
| 10 | public class OnlineStream { | 7 | public class OnlineStream { |
| 11 | - private long ptr = 0; // this is the stream ptr | 8 | + private long ptr = 0; // this is the stream ptr |
| 9 | + | ||
| 10 | + private int sampleRate = 16000; | ||
| 12 | 11 | ||
| 13 | - private int sampleRate = 16000; | ||
| 14 | - // assign ptr to this stream in construction | ||
| 15 | - public OnlineStream(long ptr, int sampleRate) { | ||
| 16 | - this.ptr = ptr; | ||
| 17 | - this.sampleRate = sampleRate; | ||
| 18 | - } | 12 | + // assign ptr to this stream in construction |
| 13 | + public OnlineStream(long ptr, int sampleRate) { | ||
| 14 | + this.ptr = ptr; | ||
| 15 | + this.sampleRate = sampleRate; | ||
| 16 | + } | ||
| 19 | 17 | ||
| 20 | - public long getPtr() { | ||
| 21 | - return ptr; | ||
| 22 | - } | 18 | + public static void loadSoLib(String soPath) { |
| 19 | + // load .so lib from the path | ||
| 20 | + System.load(soPath.trim()); // ("sherpa-onnx-jni-java"); | ||
| 21 | + } | ||
| 23 | 22 | ||
| 24 | - public void acceptWaveform(float[] samples) throws Exception { | ||
| 25 | - if (this.ptr == 0) throw new Exception("null exception for stream ptr"); | 23 | + public long getPtr() { |
| 24 | + return ptr; | ||
| 25 | + } | ||
| 26 | 26 | ||
| 27 | - // feed wave data to asr engine | ||
| 28 | - acceptWaveform(this.ptr, this.sampleRate, samples); | ||
| 29 | - } | 27 | + public void acceptWaveform(float[] samples) throws Exception { |
| 28 | + if (this.ptr == 0) throw new Exception("null exception for stream ptr"); | ||
| 30 | 29 | ||
| 31 | - public void inputFinished() { | ||
| 32 | - // add some tail padding | ||
| 33 | - int padLen = (int) (this.sampleRate * 0.3); // 0.3 seconds at 16 kHz sample rate | ||
| 34 | - float tailPaddings[] = new float[padLen]; // default value is 0 | ||
| 35 | - acceptWaveform(this.ptr, this.sampleRate, tailPaddings); | 30 | + // feed wave data to asr engine |
| 31 | + acceptWaveform(this.ptr, this.sampleRate, samples); | ||
| 32 | + } | ||
| 36 | 33 | ||
| 37 | - // tell the engine all data are feeded | ||
| 38 | - inputFinished(this.ptr); | ||
| 39 | - } | 34 | + public void inputFinished() { |
| 35 | + // add some tail padding | ||
| 36 | + int padLen = (int) (this.sampleRate * 0.3); // 0.3 seconds at 16 kHz sample rate | ||
| 37 | + float[] tailPaddings = new float[padLen]; // default value is 0 | ||
| 38 | + acceptWaveform(this.ptr, this.sampleRate, tailPaddings); | ||
| 40 | 39 | ||
| 41 | - public static void loadSoLib(String soPath) { | ||
| 42 | - // load .so lib from the path | ||
| 43 | - System.load(soPath.trim()); // ("sherpa-onnx-jni-java"); | ||
| 44 | - } | 40 | + // tell the engine all data are feeded |
| 41 | + inputFinished(this.ptr); | ||
| 42 | + } | ||
| 45 | 43 | ||
| 46 | - public void release() { | ||
| 47 | - // stream object must be release after used | ||
| 48 | - if (this.ptr == 0) return; | ||
| 49 | - deleteStream(this.ptr); | ||
| 50 | - this.ptr = 0; | ||
| 51 | - } | 44 | + public void release() { |
| 45 | + // stream object must be release after used | ||
| 46 | + if (this.ptr == 0) return; | ||
| 47 | + deleteStream(this.ptr); | ||
| 48 | + this.ptr = 0; | ||
| 49 | + } | ||
| 52 | 50 | ||
| 53 | - protected void finalize() throws Throwable { | ||
| 54 | - release(); | ||
| 55 | - } | 51 | + protected void finalize() throws Throwable { |
| 52 | + release(); | ||
| 53 | + } | ||
| 56 | 54 | ||
| 57 | - public boolean isLastFrame() throws Exception { | ||
| 58 | - if (this.ptr == 0) throw new Exception("null exception for stream ptr"); | ||
| 59 | - return isLastFrame(this.ptr); | ||
| 60 | - } | 55 | + public boolean isLastFrame() throws Exception { |
| 56 | + if (this.ptr == 0) throw new Exception("null exception for stream ptr"); | ||
| 57 | + return isLastFrame(this.ptr); | ||
| 58 | + } | ||
| 61 | 59 | ||
| 62 | - public void reSet() throws Exception { | ||
| 63 | - if (this.ptr == 0) throw new Exception("null exception for stream ptr"); | ||
| 64 | - reSet(this.ptr); | ||
| 65 | - } | 60 | + public void reSet() throws Exception { |
| 61 | + if (this.ptr == 0) throw new Exception("null exception for stream ptr"); | ||
| 62 | + reSet(this.ptr); | ||
| 63 | + } | ||
| 66 | 64 | ||
| 67 | - public int featureDim() throws Exception { | ||
| 68 | - if (this.ptr == 0) throw new Exception("null exception for stream ptr"); | ||
| 69 | - return featureDim(this.ptr); | ||
| 70 | - } | 65 | + public int featureDim() throws Exception { |
| 66 | + if (this.ptr == 0) throw new Exception("null exception for stream ptr"); | ||
| 67 | + return featureDim(this.ptr); | ||
| 68 | + } | ||
| 71 | 69 | ||
| 72 | - // JNI interface libsherpa-onnx-jni.so | ||
| 73 | - private native void acceptWaveform(long ptr, int sampleRate, float[] samples); | 70 | + // JNI interface libsherpa-onnx-jni.so |
| 71 | + private native void acceptWaveform(long ptr, int sampleRate, float[] samples); | ||
| 74 | 72 | ||
| 75 | - private native void inputFinished(long ptr); | 73 | + private native void inputFinished(long ptr); |
| 76 | 74 | ||
| 77 | - private native void deleteStream(long ptr); | 75 | + private native void deleteStream(long ptr); |
| 78 | 76 | ||
| 79 | - private native int numFramesReady(long ptr); | 77 | + private native int numFramesReady(long ptr); |
| 80 | 78 | ||
| 81 | - private native boolean isLastFrame(long ptr); | 79 | + private native boolean isLastFrame(long ptr); |
| 82 | 80 | ||
| 83 | - private native void reSet(long ptr); | 81 | + private native void reSet(long ptr); |
| 84 | 82 | ||
| 85 | - private native int featureDim(long ptr); | 83 | + private native int featureDim(long ptr); |
| 86 | } | 84 | } |
| @@ -5,25 +5,25 @@ | @@ -5,25 +5,25 @@ | ||
| 5 | package com.k2fsa.sherpa.onnx; | 5 | package com.k2fsa.sherpa.onnx; |
| 6 | 6 | ||
| 7 | public class OnlineTransducerModelConfig { | 7 | public class OnlineTransducerModelConfig { |
| 8 | - private final String encoder; | ||
| 9 | - private final String decoder; | ||
| 10 | - private final String joiner; | 8 | + private final String encoder; |
| 9 | + private final String decoder; | ||
| 10 | + private final String joiner; | ||
| 11 | 11 | ||
| 12 | - public OnlineTransducerModelConfig(String encoder, String decoder, String joiner) { | ||
| 13 | - this.encoder = encoder; | ||
| 14 | - this.decoder = decoder; | ||
| 15 | - this.joiner = joiner; | ||
| 16 | - } | 12 | + public OnlineTransducerModelConfig(String encoder, String decoder, String joiner) { |
| 13 | + this.encoder = encoder; | ||
| 14 | + this.decoder = decoder; | ||
| 15 | + this.joiner = joiner; | ||
| 16 | + } | ||
| 17 | 17 | ||
| 18 | - public String getEncoder() { | ||
| 19 | - return encoder; | ||
| 20 | - } | 18 | + public String getEncoder() { |
| 19 | + return encoder; | ||
| 20 | + } | ||
| 21 | 21 | ||
| 22 | - public String getDecoder() { | ||
| 23 | - return decoder; | ||
| 24 | - } | 22 | + public String getDecoder() { |
| 23 | + return decoder; | ||
| 24 | + } | ||
| 25 | 25 | ||
| 26 | - public String getJoiner() { | ||
| 27 | - return joiner; | ||
| 28 | - } | 26 | + public String getJoiner() { |
| 27 | + return joiner; | ||
| 28 | + } | ||
| 29 | } | 29 | } |
| @@ -1522,8 +1522,8 @@ JNIEXPORT void JNICALL Java_com_k2fsa_sherpa_onnx_SherpaOnnxOffline_delete( | @@ -1522,8 +1522,8 @@ JNIEXPORT void JNICALL Java_com_k2fsa_sherpa_onnx_SherpaOnnxOffline_delete( | ||
| 1522 | 1522 | ||
| 1523 | SHERPA_ONNX_EXTERN_C | 1523 | SHERPA_ONNX_EXTERN_C |
| 1524 | JNIEXPORT void JNICALL Java_com_k2fsa_sherpa_onnx_SherpaOnnx_reset( | 1524 | JNIEXPORT void JNICALL Java_com_k2fsa_sherpa_onnx_SherpaOnnx_reset( |
| 1525 | - JNIEnv *env, jobject /*obj*/, | ||
| 1526 | - jlong ptr, jboolean recreate, jstring keywords) { | 1525 | + JNIEnv *env, jobject /*obj*/, jlong ptr, jboolean recreate, |
| 1526 | + jstring keywords) { | ||
| 1527 | auto model = reinterpret_cast<sherpa_onnx::SherpaOnnx *>(ptr); | 1527 | auto model = reinterpret_cast<sherpa_onnx::SherpaOnnx *>(ptr); |
| 1528 | const char *p_keywords = env->GetStringUTFChars(keywords, nullptr); | 1528 | const char *p_keywords = env->GetStringUTFChars(keywords, nullptr); |
| 1529 | model->Reset(recreate, p_keywords); | 1529 | model->Reset(recreate, p_keywords); |
-
请 注册 或 登录 后发表评论