Skip to content

Commit 2dc0f91

Browse files
authored
Add C# API for Dolphin CTC models (#2089)
1 parent 18a6ed5 commit 2dc0f91

File tree

10 files changed

+52
-4
lines changed

10 files changed

+52
-4
lines changed

.github/scripts/test-dot-net.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ rm -rfv sherpa-onnx-pyannote-*
3939

4040
cd ../offline-decode-files
4141

42+
./run-dolphin-ctc.sh
43+
rm -rf sherpa-onnx-dolphin-base-ctc-multi-lang-int8-2025-04-02
44+
4245
./run-fire-red-asr.sh
4346
rm -rf sherpa-onnx-fire-red-asr-*
4447

.github/workflows/c-api.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ jobs:
9797
readelf -d ./$name
9898
fi
9999
100-
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
100+
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
101101
tar xvf sherpa-onnx-dolphin-base-ctc-multi-lang-int8-2025-04-02.tar.bz2
102102
rm sherpa-onnx-dolphin-base-ctc-multi-lang-int8-2025-04-02.tar.bz2
103103

.github/workflows/cxx-api.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ jobs:
103103
readelf -d ./$name
104104
fi
105105
106-
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
106+
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
107107
tar xvf sherpa-onnx-dolphin-base-ctc-multi-lang-int8-2025-04-02.tar.bz2
108108
rm sherpa-onnx-dolphin-base-ctc-multi-lang-int8-2025-04-02.tar.bz2
109109

c-api-examples/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ target_link_libraries(fire-red-asr-c-api sherpa-onnx-c-api)
5656
add_executable(sense-voice-c-api sense-voice-c-api.c)
5757
target_link_libraries(sense-voice-c-api sherpa-onnx-c-api)
5858

59+
add_executable(dolphin-ctc-c-api dolphin-ctc-c-api.c)
60+
target_link_libraries(dolphin-ctc-c-api sherpa-onnx-c-api)
61+
5962
add_executable(moonshine-c-api moonshine-c-api.c)
6063
target_link_libraries(moonshine-c-api sherpa-onnx-c-api)
6164

c-api-examples/dolphin-ctc-c-api.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// This file demonstrates how to use Dolphin CTC model with sherpa-onnx's C API.
77
// clang-format off
88
//
9-
// wget https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/sherpa-onnx-dolphin-base-ctc-multi-lang-int8-2025-04-02
9+
// wget https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/sherpa-onnx-dolphin-base-ctc-multi-lang-int8-2025-04-02.tar.bz2
1010
// tar xvf sherpa-onnx-dolphin-base-ctc-multi-lang-int8-2025-04-02.tar.bz2
1111
// rm sherpa-onnx-dolphin-base-ctc-multi-lang-int8-2025-04-02.tar.bz2
1212
//

cxx-api-examples/dolphin-ctc-cxx-api.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
//
88
// clang-format off
99
//
10-
// wget https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/sherpa-onnx-dolphin-base-ctc-multi-lang-int8-2025-04-02
10+
// wget https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/sherpa-onnx-dolphin-base-ctc-multi-lang-int8-2025-04-02.tar.bz2
1111
// tar xvf sherpa-onnx-dolphin-base-ctc-multi-lang-int8-2025-04-02.tar.bz2
1212
// rm sherpa-onnx-dolphin-base-ctc-multi-lang-int8-2025-04-02.tar.bz2
1313
//

dotnet-examples/offline-decode-files/Program.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ class Options
7575
[Option("nemo-ctc", Required = false, HelpText = "Path to model.onnx. Used only for NeMo CTC models")]
7676
public string NeMoCtc { get; set; } = string.Empty;
7777

78+
[Option("dolphin-model", Required = false, Default = "", HelpText = "Path to dolphin ctc model")]
79+
public string DolphinModel { get; set; } = string.Empty;
80+
7881
[Option("telespeech-ctc", Required = false, HelpText = "Path to model.onnx. Used only for TeleSpeech CTC models")]
7982
public string TeleSpeechCtc { get; set; } = string.Empty;
8083

@@ -233,6 +236,10 @@ private static void Run(Options options)
233236
{
234237
config.ModelConfig.NeMoCtc.Model = options.NeMoCtc;
235238
}
239+
else if (!string.IsNullOrEmpty(options.DolphinModel))
240+
{
241+
config.ModelConfig.Dolphin.Model = options.DolphinModel;
242+
}
236243
else if (!string.IsNullOrEmpty(options.TeleSpeechCtc))
237244
{
238245
config.ModelConfig.TeleSpeechCtc = options.TeleSpeechCtc;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
dotnet run \
13+
--tokens=./sherpa-onnx-dolphin-base-ctc-multi-lang-int8-2025-04-02/tokens.txt \
14+
--dolphin-model=./sherpa-onnx-dolphin-base-ctc-multi-lang-int8-2025-04-02/model.int8.onnx \
15+
--num-threads=1 \
16+
--files ./sherpa-onnx-dolphin-base-ctc-multi-lang-int8-2025-04-02/test_wavs/0.wav
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/// Copyright (c) 2025 Xiaomi Corporation (authors: Fangjun Kuang)
2+
3+
using System.Runtime.InteropServices;
4+
5+
namespace SherpaOnnx
6+
{
7+
[StructLayout(LayoutKind.Sequential)]
8+
public struct OfflineDolphinModelConfig
9+
{
10+
public OfflineDolphinModelConfig()
11+
{
12+
Model = "";
13+
}
14+
[MarshalAs(UnmanagedType.LPStr)]
15+
public string Model;
16+
}
17+
}

scripts/dotnet/OfflineModelConfig.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public OfflineModelConfig()
2626
SenseVoice = new OfflineSenseVoiceModelConfig();
2727
Moonshine = new OfflineMoonshineModelConfig();
2828
FireRedAsr = new OfflineFireRedAsrModelConfig();
29+
Dolphin = new OfflineDolphinModelConfig();
2930
}
3031
public OfflineTransducerModelConfig Transducer;
3132
public OfflineParaformerModelConfig Paraformer;
@@ -58,5 +59,6 @@ public OfflineModelConfig()
5859
public OfflineSenseVoiceModelConfig SenseVoice;
5960
public OfflineMoonshineModelConfig Moonshine;
6061
public OfflineFireRedAsrModelConfig FireRedAsr;
62+
public OfflineDolphinModelConfig Dolphin;
6163
}
6264
}

0 commit comments

Comments
 (0)