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
77 lines
2.0 KiB
ObjectPascal
77 lines
2.0 KiB
ObjectPascal
{ Copyright (c) 2025 Xiaomi Corporation }
|
|
|
|
{
|
|
This file shows how to use a non-streaming Zipformer CTC model
|
|
to decode files.
|
|
|
|
You can download the model files from
|
|
https://github.com/k2-fsa/sherpa-onnx/releases/tag/asr-models
|
|
}
|
|
|
|
program zipformer_ctc;
|
|
|
|
{$mode objfpc}
|
|
|
|
uses
|
|
sherpa_onnx,
|
|
DateUtils,
|
|
SysUtils;
|
|
|
|
var
|
|
Wave: TSherpaOnnxWave;
|
|
WaveFilename: AnsiString;
|
|
|
|
Config: TSherpaOnnxOfflineRecognizerConfig;
|
|
Recognizer: TSherpaOnnxOfflineRecognizer;
|
|
Stream: TSherpaOnnxOfflineStream;
|
|
RecognitionResult: TSherpaOnnxOfflineRecognizerResult;
|
|
|
|
Start: TDateTime;
|
|
Stop: TDateTime;
|
|
|
|
Elapsed: Single;
|
|
Duration: Single;
|
|
RealTimeFactor: Single;
|
|
begin
|
|
Initialize(Config);
|
|
|
|
Config.ModelConfig.ZipformerCtc.Model := './sherpa-onnx-zipformer-ctc-zh-int8-2025-07-03/model.int8.onnx';
|
|
Config.ModelConfig.Tokens := './sherpa-onnx-zipformer-ctc-zh-int8-2025-07-03/tokens.txt';
|
|
Config.ModelConfig.Provider := 'cpu';
|
|
Config.ModelConfig.NumThreads := 1;
|
|
Config.ModelConfig.Debug := False;
|
|
|
|
WaveFilename := './sherpa-onnx-zipformer-ctc-zh-int8-2025-07-03/test_wavs/0.wav';
|
|
|
|
Wave := SherpaOnnxReadWave(WaveFilename);
|
|
|
|
Recognizer := TSherpaOnnxOfflineRecognizer.Create(Config);
|
|
Stream := Recognizer.CreateStream();
|
|
Start := Now;
|
|
|
|
Stream.AcceptWaveform(Wave.Samples, Wave.SampleRate);
|
|
Recognizer.Decode(Stream);
|
|
|
|
RecognitionResult := Recognizer.GetResult(Stream);
|
|
|
|
Stop := Now;
|
|
|
|
Elapsed := MilliSecondsBetween(Stop, Start) / 1000;
|
|
Duration := Length(Wave.Samples) / Wave.SampleRate;
|
|
RealTimeFactor := Elapsed / Duration;
|
|
|
|
WriteLn(RecognitionResult.ToString);
|
|
WriteLn(Format('NumThreads %d', [Config.ModelConfig.NumThreads]));
|
|
WriteLn(Format('Elapsed %.3f s', [Elapsed]));
|
|
WriteLn(Format('Wave duration %.3f s', [Duration]));
|
|
WriteLn(Format('RTF = %.3f/%.3f = %.3f', [Elapsed, Duration, RealTimeFactor]));
|
|
|
|
{Free resources to avoid memory leak.
|
|
|
|
Note: You don't need to invoke them for this simple script.
|
|
However, you have to invoke them in your own large/complex project.
|
|
}
|
|
FreeAndNil(Stream);
|
|
FreeAndNil(Recognizer);
|
|
end.
|