mirror of
https://github.com/k2-fsa/sherpa-onnx.git
synced 2026-01-09 07:41:06 +08:00
This PR adds support for Wenet non-streaming CTC models to sherpa-onnx by introducing the SherpaOnnxOfflineWenetCtcModelConfig struct and integrating it across all language bindings and APIs. The implementation follows the same pattern as other CTC model types like Zipformer CTC. - Introduces SherpaOnnxOfflineWenetCtcModelConfig struct with a single model field for the ONNX model path - Adds the new config to SherpaOnnxOfflineModelConfig and updates all language bindings (C++, Pascal, Kotlin, Java, Go, C#, Swift, JavaScript, etc.) - Provides comprehensive examples and tests across all supported platforms and languages
55 lines
1.7 KiB
Java
55 lines
1.7 KiB
Java
// Copyright 2025 Xiaomi Corporation
|
|
|
|
// This file shows how to use an offline Wenet CTC model,
|
|
// i.e., non-streaming Wenet CTC model,
|
|
// to decode files.
|
|
import com.k2fsa.sherpa.onnx.*;
|
|
|
|
public class NonStreamingDecodeFileWenetCtc {
|
|
public static void main(String[] args) {
|
|
// please refer to
|
|
// https://k2-fsa.github.io/sherpa/onnx/sense-voice/index.html
|
|
// to download model files
|
|
String model =
|
|
"sherpa-onnx-wenetspeech-yue-u2pp-conformer-ctc-zh-en-cantonese-int8-2025-09-10/model.int8.onnx";
|
|
|
|
String tokens =
|
|
"sherpa-onnx-wenetspeech-yue-u2pp-conformer-ctc-zh-en-cantonese-int8-2025-09-10/tokens.txt";
|
|
|
|
String waveFilename =
|
|
"sherpa-onnx-wenetspeech-yue-u2pp-conformer-ctc-zh-en-cantonese-int8-2025-09-10/test_wavs/yue-0.wav";
|
|
|
|
WaveReader reader = new WaveReader(waveFilename);
|
|
|
|
OfflineWenetCtcModelConfig wenetCtc =
|
|
OfflineWenetCtcModelConfig.builder().setModel(model).build();
|
|
|
|
OfflineModelConfig modelConfig =
|
|
OfflineModelConfig.builder()
|
|
.setWenetCtc(wenetCtc)
|
|
.setTokens(tokens)
|
|
.setNumThreads(1)
|
|
.setDebug(true)
|
|
.build();
|
|
|
|
OfflineRecognizerConfig config =
|
|
OfflineRecognizerConfig.builder()
|
|
.setOfflineModelConfig(modelConfig)
|
|
.setDecodingMethod("greedy_search")
|
|
.build();
|
|
|
|
OfflineRecognizer recognizer = new OfflineRecognizer(config);
|
|
OfflineStream stream = recognizer.createStream();
|
|
stream.acceptWaveform(reader.getSamples(), reader.getSampleRate());
|
|
|
|
recognizer.decode(stream);
|
|
|
|
String text = recognizer.getResult(stream).getText();
|
|
|
|
System.out.printf("filename:%s\nresult:%s\n", waveFilename, text);
|
|
|
|
stream.release();
|
|
recognizer.release();
|
|
}
|
|
}
|