mirror of
https://github.com/k2-fsa/sherpa-onnx.git
synced 2026-11-11 21:40:58 +08:00
Add various language bindings for streaming T-one Russian ASR models (#2576)
This PR adds support for streaming T-one Russian ASR models across various language bindings in the sherpa-onnx library. The changes enable T-one CTC (Connectionist Temporal Classification) model integration by adding new configuration structures and example implementations. - Introduces OnlineToneCtcModelConfig structures across all language bindings (C, C++, Swift, Java, Kotlin, Go, etc.) - Adds T-one CTC model support to WASM implementations for both ASR and keyword spotting - Provides comprehensive example implementations demonstrating T-one model usage in multiple programming languages
This commit is contained in:
1 parent
858b5052a2
commit
686b909e2f
62 files changed
+1351
-96
No files matched your search
@@ -0,0 +1,53 @@
|
||||
// Copyright 2024 Xiaomi Corporation
|
||||
|
||||
// This file shows how to use an online T-one CTC model, i.e.,
|
||||
// streaming T-one CTC model, to decode files.
|
||||
import com.k2fsa.sherpa.onnx.*;
|
||||
|
||||
public class StreamingDecodeFileToneCtc {
|
||||
public static void main(String[] args) {
|
||||
String model = "./sherpa-onnx-streaming-t-one-russian-2025-09-08/model.onnx";
|
||||
String tokens = "./sherpa-onnx-streaming-t-one-russian-2025-09-08/tokens.txt";
|
||||
String waveFilename = "./sherpa-onnx-streaming-t-one-russian-2025-09-08/0.wav";
|
||||
|
||||
WaveReader reader = new WaveReader(waveFilename);
|
||||
|
||||
OnlineToneCtcModelConfig ctc = OnlineToneCtcModelConfig.builder().setModel(model).build();
|
||||
|
||||
OnlineModelConfig modelConfig =
|
||||
OnlineModelConfig.builder()
|
||||
.setToneCtc(ctc)
|
||||
.setTokens(tokens)
|
||||
.setNumThreads(1)
|
||||
.setDebug(true)
|
||||
.build();
|
||||
|
||||
OnlineRecognizerConfig config =
|
||||
OnlineRecognizerConfig.builder()
|
||||
.setOnlineModelConfig(modelConfig)
|
||||
.setDecodingMethod("greedy_search")
|
||||
.build();
|
||||
|
||||
OnlineRecognizer recognizer = new OnlineRecognizer(config);
|
||||
OnlineStream stream = recognizer.createStream();
|
||||
|
||||
float[] leftPaddings = new float[(int) (0.3 * reader.getSampleRate())];
|
||||
stream.acceptWaveform(leftPaddings, reader.getSampleRate());
|
||||
|
||||
stream.acceptWaveform(reader.getSamples(), reader.getSampleRate());
|
||||
|
||||
float[] tailPaddings = new float[(int) (0.6 * reader.getSampleRate())];
|
||||
stream.acceptWaveform(tailPaddings, reader.getSampleRate());
|
||||
|
||||
while (recognizer.isReady(stream)) {
|
||||
recognizer.decode(stream);
|
||||
}
|
||||
|
||||
String text = recognizer.getResult(stream).getText();
|
||||
|
||||
System.out.printf("filename:%s\nresult:%s\n", waveFilename, text);
|
||||
|
||||
stream.release();
|
||||
recognizer.release();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user