This PR adds support for non-streaming Zipformer CTC ASR models across multiple language bindings, WebAssembly, examples, and CI workflows. - Introduces a new OfflineZipformerCtcModelConfig in C/C++, Python, Swift, Java, Kotlin, Go, Dart, Pascal, and C# APIs - Updates initialization, freeing, and recognition logic to include Zipformer CTC in WASM and Node.js - Adds example scripts and CI steps for downloading, building, and running Zipformer CTC models Model doc is available at https://k2-fsa.github.io/sherpa/onnx/pretrained_models/offline-ctc/icefall/zipformer.html
51 lines
1.7 KiB
Java
51 lines
1.7 KiB
Java
// Copyright 2025 Xiaomi Corporation
|
|
|
|
// This file shows how to use an offline Zipformer CTC model,
|
|
// i.e., non-streaming Zipformer CTC model,
|
|
// to decode files.
|
|
import com.k2fsa.sherpa.onnx.*;
|
|
|
|
public class NonStreamingDecodeFileZipformerCtc {
|
|
public static void main(String[] args) {
|
|
// please refer to
|
|
// https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/sherpa-onnx-zipformer-ctc-zh-int8-2025-07-03.tar.bz2
|
|
// to download model files
|
|
String model = "./sherpa-onnx-zipformer-ctc-zh-int8-2025-07-03/model.int8.onnx";
|
|
String tokens = "./sherpa-onnx-zipformer-ctc-zh-int8-2025-07-03/tokens.txt";
|
|
|
|
String waveFilename = "./sherpa-onnx-zipformer-ctc-zh-int8-2025-07-03/test_wavs/0.wav";
|
|
|
|
WaveReader reader = new WaveReader(waveFilename);
|
|
|
|
OfflineZipformerCtcModelConfig zipformerCtc =
|
|
OfflineZipformerCtcModelConfig.builder().setModel(model).build();
|
|
|
|
OfflineModelConfig modelConfig =
|
|
OfflineModelConfig.builder()
|
|
.setZipformerCtc(zipformerCtc)
|
|
.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();
|
|
}
|
|
}
|