Skip to content

Commit ba7d8b6

Browse files
authored
Add Go API for Dolphin CTC models (#2090)
1 parent 2dc0f91 commit ba7d8b6

File tree

8 files changed

+36
-3
lines changed

8 files changed

+36
-3
lines changed

.github/workflows/test-go.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,10 @@ jobs:
179179
go build
180180
ls -lh
181181
182+
echo "Test Dolphin CTC"
183+
./run-dolphin-ctc-base.sh
184+
rm -rf sherpa-onnx-dolphin-*
185+
182186
echo "Test FireRedAsr"
183187
./run-fire-red-asr.sh
184188
rm -rf sherpa-onnx-fire-red-asr-*

c-api-examples/vad-moonshine-c-api.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ int32_t main() {
8686
vadConfig.num_threads = 1;
8787
vadConfig.debug = 1;
8888

89-
SherpaOnnxVoiceActivityDetector *vad =
89+
const SherpaOnnxVoiceActivityDetector *vad =
9090
SherpaOnnxCreateVoiceActivityDetector(&vadConfig, 30);
9191

9292
if (vad == NULL) {

c-api-examples/vad-sense-voice-c-api.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ int32_t main() {
8787
vadConfig.num_threads = 1;
8888
vadConfig.debug = 1;
8989

90-
SherpaOnnxVoiceActivityDetector *vad =
90+
const SherpaOnnxVoiceActivityDetector *vad =
9191
SherpaOnnxCreateVoiceActivityDetector(&vadConfig, 30);
9292

9393
if (vad == NULL) {

c-api-examples/vad-whisper-c-api.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ int32_t main() {
8484
vadConfig.num_threads = 1;
8585
vadConfig.debug = 1;
8686

87-
SherpaOnnxVoiceActivityDetector *vad =
87+
const SherpaOnnxVoiceActivityDetector *vad =
8888
SherpaOnnxCreateVoiceActivityDetector(&vadConfig, 30);
8989

9090
if (vad == NULL) {

go-api-examples/non-streaming-decode-files/main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ func main() {
2828

2929
flag.StringVar(&config.ModelConfig.NemoCTC.Model, "nemo-ctc", "", "Path to the NeMo CTC model")
3030

31+
flag.StringVar(&config.ModelConfig.Dolphin.Model, "dolphin-model", "", "Path to the Dolphin CTC model")
32+
3133
flag.StringVar(&config.ModelConfig.FireRedAsr.Encoder, "fire-red-asr-encoder", "", "Path to the FireRedAsr encoder model")
3234
flag.StringVar(&config.ModelConfig.FireRedAsr.Decoder, "fire-red-asr-decoder", "", "Path to the FireRedAsr decoder model")
3335

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env bash
2+
3+
set -ex
4+
5+
if [ ! -f ./sherpa-onnx-dolphin-base-ctc-multi-lang-int8-2025-04-02/model.int8.onnx ]; then
6+
curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/sherpa-onnx-dolphin-base-ctc-multi-lang-int8-2025-04-02.tar.bz2
7+
tar xvf sherpa-onnx-dolphin-base-ctc-multi-lang-int8-2025-04-02.tar.bz2
8+
rm sherpa-onnx-dolphin-base-ctc-multi-lang-int8-2025-04-02.tar.bz2
9+
ls -lh sherpa-onnx-dolphin-base-ctc-multi-lang-int8-2025-04-02
10+
fi
11+
12+
go mod tidy
13+
go build
14+
15+
./non-streaming-decode-files \
16+
--dolphin-model ./sherpa-onnx-dolphin-base-ctc-multi-lang-int8-2025-04-02/model.int8.onnx \
17+
--tokens ./sherpa-onnx-dolphin-base-ctc-multi-lang-int8-2025-04-02/tokens.txt \
18+
--debug 0 \
19+
./sherpa-onnx-dolphin-base-ctc-multi-lang-int8-2025-04-02/test_wavs/0.wav
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../go-api-examples/non-streaming-decode-files/run-dolphin-ctc-base.sh

scripts/go/sherpa_onnx.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,10 @@ type OfflineNemoEncDecCtcModelConfig struct {
377377
Model string // Path to the model, e.g., model.onnx or model.int8.onnx
378378
}
379379

380+
type OfflineDolphinModelConfig struct {
381+
Model string // Path to the model, e.g., model.onnx or model.int8.onnx
382+
}
383+
380384
type OfflineWhisperModelConfig struct {
381385
Encoder string
382386
Decoder string
@@ -422,6 +426,7 @@ type OfflineModelConfig struct {
422426
SenseVoice OfflineSenseVoiceModelConfig
423427
Moonshine OfflineMoonshineModelConfig
424428
FireRedAsr OfflineFireRedAsrModelConfig
429+
Dolphin OfflineDolphinModelConfig
425430
Tokens string // Path to tokens.txt
426431

427432
// Number of threads to use for neural network computation
@@ -512,6 +517,8 @@ func newCOfflineRecognizerConfig(config *OfflineRecognizerConfig) *C.struct_Sher
512517
c.model_config.fire_red_asr.encoder = C.CString(config.ModelConfig.FireRedAsr.Encoder)
513518
c.model_config.fire_red_asr.decoder = C.CString(config.ModelConfig.FireRedAsr.Decoder)
514519

520+
c.model_config.dolphin.model = C.CString(config.ModelConfig.Dolphin.Model)
521+
515522
c.model_config.tokens = C.CString(config.ModelConfig.Tokens)
516523

517524
c.model_config.num_threads = C.int(config.ModelConfig.NumThreads)

0 commit comments

Comments
 (0)