Skip to content

Commit d0597dc

Browse files
committed
Add Pascal API for Zipformer CTC
1 parent d12aa0e commit d0597dc

13 files changed

Lines changed: 344 additions & 9 deletions

File tree

.github/workflows/pascal.yaml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
strategy:
3838
fail-fast: false
3939
matrix:
40-
os: [ubuntu-latest, macos-latest, macos-13, windows-latest]
40+
os: [ubuntu-latest, macos-latest, macos-13, windows-latest, ubuntu-22.04-arm]
4141

4242
steps:
4343
- uses: actions/checkout@v4
@@ -56,7 +56,7 @@ jobs:
5656
key: ${{ matrix.os }}
5757

5858
- name: Install Free pascal compiler (ubuntu)
59-
if: matrix.os == 'ubuntu-latest'
59+
if: matrix.os == 'ubuntu-latest' || matrix.os == 'ubuntu-22.04-arm'
6060
shell: bash
6161
run: |
6262
sudo apt-get update
@@ -156,6 +156,10 @@ jobs:
156156
157157
pushd non-streaming-asr
158158
159+
./run-zipformer-ctc.sh
160+
rm -rf sherpa-onnx-*
161+
echo "---"
162+
159163
./run-dolphin-ctc.sh
160164
rm -rf sherpa-onnx-*
161165
echo "---"
@@ -264,9 +268,12 @@ jobs:
264268
265269
cd ./pascal-api-examples
266270
267-
268271
pushd vad-with-non-streaming-asr
269272
273+
time ./run-vad-with-zipformer-ctc.sh
274+
rm -rf sherpa-onnx-*
275+
echo "---"
276+
270277
time ./run-vad-with-dolphin-ctc.sh
271278
rm -rf sherpa-onnx-*
272279
echo "---"

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ We also have spaces built using WebAssembly. They are listed below:
142142
|----------------------------------------|------------------------------------|-----------------------------------|
143143
| Speaker diarization | [Address][apk-speaker-diarization] | [点此][apk-speaker-diarization-cn]|
144144
| Streaming speech recognition | [Address][apk-streaming-asr] | [点此][apk-streaming-asr-cn] |
145+
| Simulated-streaming speech recognition | [Address][apk-simula-streaming-asr]| [点此][apk-simula-streaming-asr-cn]|
145146
| Text-to-speech | [Address][apk-tts] | [点此][apk-tts-cn] |
146147
| Voice activity detection (VAD) | [Address][apk-vad] | [点此][apk-vad-cn] |
147148
| VAD + non-streaming speech recognition | [Address][apk-vad-asr] | [点此][apk-vad-asr-cn] |
@@ -455,6 +456,8 @@ It uses sherpa-onnx for speech-to-text and text-to-speech.
455456
[apk-speaker-diarization-cn]: https://k2-fsa.github.io/sherpa/onnx/speaker-diarization/apk-cn.html
456457
[apk-streaming-asr]: https://k2-fsa.github.io/sherpa/onnx/android/apk.html
457458
[apk-streaming-asr-cn]: https://k2-fsa.github.io/sherpa/onnx/android/apk-cn.html
459+
[apk-simula-streaming-asr]: https://k2-fsa.github.io/sherpa/onnx/android/apk-simulate-streaming-asr.html
460+
[apk-simula-streaming-asr-cn]: https://k2-fsa.github.io/sherpa/onnx/android/apk-simulate-streaming-asr-cn.html
458461
[apk-tts]: https://k2-fsa.github.io/sherpa/onnx/tts/apk-engine.html
459462
[apk-tts-cn]: https://k2-fsa.github.io/sherpa/onnx/tts/apk-engine-cn.html
460463
[apk-vad]: https://k2-fsa.github.io/sherpa/onnx/vad/apk.html

dart-api-examples/non-streaming-asr/bin/zipformer-ctc.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2024 Xiaomi Corporation
1+
// Copyright (c) 2025 Xiaomi Corporation
22
import 'dart:io';
33

44
import 'package:args/args.dart';

dart-api-examples/vad-with-non-streaming-asr/bin/zipformer-ctc.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2024 Xiaomi Corporation
1+
// Copyright (c) 2025 Xiaomi Corporation
22
import 'dart:io';
33
import 'dart:typed_data';
44

java-api-examples/NonStreamingDecodeFileZipformerCtc.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2024 Xiaomi Corporation
1+
// Copyright 2025 Xiaomi Corporation
22

33
// This file shows how to use an offline Zipformer CTC model,
44
// i.e., non-streaming Zipformer CTC model,

nodejs-addon-examples/test_vad_asr_non_streaming_zipformer_ctc_microphone.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2023-2024 Xiaomi Corporation (authors: Fangjun Kuang)
1+
// Copyright (c) 2025 Xiaomi Corporation (authors: Fangjun Kuang)
22
//
33
const portAudio = require('naudiodon2');
44
// console.log(portAudio.getDevices());

pascal-api-examples/non-streaming-asr/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ sense_voice
99
telespeech_ctc
1010
moonshine
1111
dolphin_ctc
12+
zipformer_ctc
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env bash
2+
3+
set -ex
4+
5+
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
6+
SHERPA_ONNX_DIR=$(cd $SCRIPT_DIR/../.. && pwd)
7+
8+
echo "SHERPA_ONNX_DIR: $SHERPA_ONNX_DIR"
9+
10+
if [[ ! -f ../../build/install/lib/libsherpa-onnx-c-api.dylib && ! -f ../../build/install/lib/libsherpa-onnx-c-api.so && ! -f ../../build/install/lib/sherpa-onnx-c-api.dll ]]; then
11+
mkdir -p ../../build
12+
pushd ../../build
13+
cmake \
14+
-DCMAKE_INSTALL_PREFIX=./install \
15+
-DSHERPA_ONNX_ENABLE_PYTHON=OFF \
16+
-DSHERPA_ONNX_ENABLE_TESTS=OFF \
17+
-DSHERPA_ONNX_ENABLE_CHECK=OFF \
18+
-DBUILD_SHARED_LIBS=ON \
19+
-DSHERPA_ONNX_ENABLE_PORTAUDIO=OFF \
20+
..
21+
22+
cmake --build . --target install --config Release
23+
ls -lh lib
24+
popd
25+
fi
26+
27+
if [ ! -f ./sherpa-onnx-zipformer-ctc-zh-int8-2025-07-03/tokens.txt ]; then
28+
curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/sherpa-onnx-zipformer-ctc-zh-int8-2025-07-03.tar.bz2
29+
30+
tar xvf sherpa-onnx-zipformer-ctc-zh-int8-2025-07-03.tar.bz2
31+
rm sherpa-onnx-zipformer-ctc-zh-int8-2025-07-03.tar.bz2
32+
fi
33+
34+
fpc \
35+
-dSHERPA_ONNX_USE_SHARED_LIBS \
36+
-Fu$SHERPA_ONNX_DIR/sherpa-onnx/pascal-api \
37+
-Fl$SHERPA_ONNX_DIR/build/install/lib \
38+
./zipformer_ctc.pas
39+
40+
export LD_LIBRARY_PATH=$SHERPA_ONNX_DIR/build/install/lib:$LD_LIBRARY_PATH
41+
export DYLD_LIBRARY_PATH=$SHERPA_ONNX_DIR/build/install/lib:$DYLD_LIBRARY_PATH
42+
43+
./zipformer_ctc
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
{ Copyright (c) 2025 Xiaomi Corporation }
2+
3+
{
4+
This file shows how to use a non-streaming Zipformer CTC model
5+
to decode files.
6+
7+
You can download the model files from
8+
https://github.com/k2-fsa/sherpa-onnx/releases/tag/asr-models
9+
}
10+
11+
program zipformer_ctc;
12+
13+
{$mode objfpc}
14+
15+
uses
16+
sherpa_onnx,
17+
DateUtils,
18+
SysUtils;
19+
20+
var
21+
Wave: TSherpaOnnxWave;
22+
WaveFilename: AnsiString;
23+
24+
Config: TSherpaOnnxOfflineRecognizerConfig;
25+
Recognizer: TSherpaOnnxOfflineRecognizer;
26+
Stream: TSherpaOnnxOfflineStream;
27+
RecognitionResult: TSherpaOnnxOfflineRecognizerResult;
28+
29+
Start: TDateTime;
30+
Stop: TDateTime;
31+
32+
Elapsed: Single;
33+
Duration: Single;
34+
RealTimeFactor: Single;
35+
begin
36+
Initialize(Config);
37+
38+
Config.ModelConfig.ZipformerCtC.Model := './sherpa-onnx-zipformer-ctc-zh-int8-2025-07-03/model.int8.onnx';
39+
Config.ModelConfig.Tokens := './sherpa-onnx-zipformer-ctc-zh-int8-2025-07-03/tokens.txt';
40+
Config.ModelConfig.Provider := 'cpu';
41+
Config.ModelConfig.NumThreads := 1;
42+
Config.ModelConfig.Debug := False;
43+
44+
WaveFilename := './sherpa-onnx-zipformer-ctc-zh-int8-2025-07-03/test_wavs/0.wav';
45+
46+
Wave := SherpaOnnxReadWave(WaveFilename);
47+
48+
Recognizer := TSherpaOnnxOfflineRecognizer.Create(Config);
49+
Stream := Recognizer.CreateStream();
50+
Start := Now;
51+
52+
Stream.AcceptWaveform(Wave.Samples, Wave.SampleRate);
53+
Recognizer.Decode(Stream);
54+
55+
RecognitionResult := Recognizer.GetResult(Stream);
56+
57+
Stop := Now;
58+
59+
Elapsed := MilliSecondsBetween(Stop, Start) / 1000;
60+
Duration := Length(Wave.Samples) / Wave.SampleRate;
61+
RealTimeFactor := Elapsed / Duration;
62+
63+
WriteLn(RecognitionResult.ToString);
64+
WriteLn(Format('NumThreads %d', [Config.ModelConfig.NumThreads]));
65+
WriteLn(Format('Elapsed %.3f s', [Elapsed]));
66+
WriteLn(Format('Wave duration %.3f s', [Duration]));
67+
WriteLn(Format('RTF = %.3f/%.3f = %.3f', [Elapsed, Duration, RealTimeFactor]));
68+
69+
{Free resources to avoid memory leak.
70+
71+
Note: You don't need to invoke them for this simple script.
72+
However, you have to invoke them in your own large/complex project.
73+
}
74+
FreeAndNil(Stream);
75+
FreeAndNil(Recognizer);
76+
end.

pascal-api-examples/vad-with-non-streaming-asr/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22
vad_with_whisper
33
vad_with_sense_voice
44
vad_with_moonshine
5+
vad_with_zipformer_ctc
6+
vad_with_dolphin

0 commit comments

Comments
 (0)