Add C# API for Dolphin CTC models (#2089)
This commit is contained in:
3
.github/scripts/test-dot-net.sh
vendored
3
.github/scripts/test-dot-net.sh
vendored
@@ -39,6 +39,9 @@ rm -rfv sherpa-onnx-pyannote-*
|
|||||||
|
|
||||||
cd ../offline-decode-files
|
cd ../offline-decode-files
|
||||||
|
|
||||||
|
./run-dolphin-ctc.sh
|
||||||
|
rm -rf sherpa-onnx-dolphin-base-ctc-multi-lang-int8-2025-04-02
|
||||||
|
|
||||||
./run-fire-red-asr.sh
|
./run-fire-red-asr.sh
|
||||||
rm -rf sherpa-onnx-fire-red-asr-*
|
rm -rf sherpa-onnx-fire-red-asr-*
|
||||||
|
|
||||||
|
|||||||
2
.github/workflows/c-api.yaml
vendored
2
.github/workflows/c-api.yaml
vendored
@@ -97,7 +97,7 @@ jobs:
|
|||||||
readelf -d ./$name
|
readelf -d ./$name
|
||||||
fi
|
fi
|
||||||
|
|
||||||
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
|
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
|
||||||
tar xvf sherpa-onnx-dolphin-base-ctc-multi-lang-int8-2025-04-02.tar.bz2
|
tar xvf sherpa-onnx-dolphin-base-ctc-multi-lang-int8-2025-04-02.tar.bz2
|
||||||
rm sherpa-onnx-dolphin-base-ctc-multi-lang-int8-2025-04-02.tar.bz2
|
rm sherpa-onnx-dolphin-base-ctc-multi-lang-int8-2025-04-02.tar.bz2
|
||||||
|
|
||||||
|
|||||||
2
.github/workflows/cxx-api.yaml
vendored
2
.github/workflows/cxx-api.yaml
vendored
@@ -103,7 +103,7 @@ jobs:
|
|||||||
readelf -d ./$name
|
readelf -d ./$name
|
||||||
fi
|
fi
|
||||||
|
|
||||||
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
|
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
|
||||||
tar xvf sherpa-onnx-dolphin-base-ctc-multi-lang-int8-2025-04-02.tar.bz2
|
tar xvf sherpa-onnx-dolphin-base-ctc-multi-lang-int8-2025-04-02.tar.bz2
|
||||||
rm sherpa-onnx-dolphin-base-ctc-multi-lang-int8-2025-04-02.tar.bz2
|
rm sherpa-onnx-dolphin-base-ctc-multi-lang-int8-2025-04-02.tar.bz2
|
||||||
|
|
||||||
|
|||||||
@@ -56,6 +56,9 @@ target_link_libraries(fire-red-asr-c-api sherpa-onnx-c-api)
|
|||||||
add_executable(sense-voice-c-api sense-voice-c-api.c)
|
add_executable(sense-voice-c-api sense-voice-c-api.c)
|
||||||
target_link_libraries(sense-voice-c-api sherpa-onnx-c-api)
|
target_link_libraries(sense-voice-c-api sherpa-onnx-c-api)
|
||||||
|
|
||||||
|
add_executable(dolphin-ctc-c-api dolphin-ctc-c-api.c)
|
||||||
|
target_link_libraries(dolphin-ctc-c-api sherpa-onnx-c-api)
|
||||||
|
|
||||||
add_executable(moonshine-c-api moonshine-c-api.c)
|
add_executable(moonshine-c-api moonshine-c-api.c)
|
||||||
target_link_libraries(moonshine-c-api sherpa-onnx-c-api)
|
target_link_libraries(moonshine-c-api sherpa-onnx-c-api)
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
// This file demonstrates how to use Dolphin CTC model with sherpa-onnx's C API.
|
// This file demonstrates how to use Dolphin CTC model with sherpa-onnx's C API.
|
||||||
// clang-format off
|
// clang-format off
|
||||||
//
|
//
|
||||||
// wget https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/sherpa-onnx-dolphin-base-ctc-multi-lang-int8-2025-04-02
|
// 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
|
||||||
// tar xvf sherpa-onnx-dolphin-base-ctc-multi-lang-int8-2025-04-02.tar.bz2
|
// tar xvf sherpa-onnx-dolphin-base-ctc-multi-lang-int8-2025-04-02.tar.bz2
|
||||||
// rm sherpa-onnx-dolphin-base-ctc-multi-lang-int8-2025-04-02.tar.bz2
|
// rm sherpa-onnx-dolphin-base-ctc-multi-lang-int8-2025-04-02.tar.bz2
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
//
|
//
|
||||||
// clang-format off
|
// clang-format off
|
||||||
//
|
//
|
||||||
// wget https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/sherpa-onnx-dolphin-base-ctc-multi-lang-int8-2025-04-02
|
// 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
|
||||||
// tar xvf sherpa-onnx-dolphin-base-ctc-multi-lang-int8-2025-04-02.tar.bz2
|
// tar xvf sherpa-onnx-dolphin-base-ctc-multi-lang-int8-2025-04-02.tar.bz2
|
||||||
// rm sherpa-onnx-dolphin-base-ctc-multi-lang-int8-2025-04-02.tar.bz2
|
// rm sherpa-onnx-dolphin-base-ctc-multi-lang-int8-2025-04-02.tar.bz2
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -75,6 +75,9 @@ class OfflineDecodeFiles
|
|||||||
[Option("nemo-ctc", Required = false, HelpText = "Path to model.onnx. Used only for NeMo CTC models")]
|
[Option("nemo-ctc", Required = false, HelpText = "Path to model.onnx. Used only for NeMo CTC models")]
|
||||||
public string NeMoCtc { get; set; } = string.Empty;
|
public string NeMoCtc { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
[Option("dolphin-model", Required = false, Default = "", HelpText = "Path to dolphin ctc model")]
|
||||||
|
public string DolphinModel { get; set; } = string.Empty;
|
||||||
|
|
||||||
[Option("telespeech-ctc", Required = false, HelpText = "Path to model.onnx. Used only for TeleSpeech CTC models")]
|
[Option("telespeech-ctc", Required = false, HelpText = "Path to model.onnx. Used only for TeleSpeech CTC models")]
|
||||||
public string TeleSpeechCtc { get; set; } = string.Empty;
|
public string TeleSpeechCtc { get; set; } = string.Empty;
|
||||||
|
|
||||||
@@ -233,6 +236,10 @@ to download pre-trained Tdnn models.
|
|||||||
{
|
{
|
||||||
config.ModelConfig.NeMoCtc.Model = options.NeMoCtc;
|
config.ModelConfig.NeMoCtc.Model = options.NeMoCtc;
|
||||||
}
|
}
|
||||||
|
else if (!string.IsNullOrEmpty(options.DolphinModel))
|
||||||
|
{
|
||||||
|
config.ModelConfig.Dolphin.Model = options.DolphinModel;
|
||||||
|
}
|
||||||
else if (!string.IsNullOrEmpty(options.TeleSpeechCtc))
|
else if (!string.IsNullOrEmpty(options.TeleSpeechCtc))
|
||||||
{
|
{
|
||||||
config.ModelConfig.TeleSpeechCtc = options.TeleSpeechCtc;
|
config.ModelConfig.TeleSpeechCtc = options.TeleSpeechCtc;
|
||||||
|
|||||||
16
dotnet-examples/offline-decode-files/run-dolphin-ctc.sh
Executable file
16
dotnet-examples/offline-decode-files/run-dolphin-ctc.sh
Executable file
@@ -0,0 +1,16 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
set -ex
|
||||||
|
|
||||||
|
if [ ! -f ./sherpa-onnx-dolphin-base-ctc-multi-lang-int8-2025-04-02/model.int8.onnx ]; then
|
||||||
|
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
|
||||||
|
tar xvf sherpa-onnx-dolphin-base-ctc-multi-lang-int8-2025-04-02.tar.bz2
|
||||||
|
rm sherpa-onnx-dolphin-base-ctc-multi-lang-int8-2025-04-02.tar.bz2
|
||||||
|
ls -lh sherpa-onnx-dolphin-base-ctc-multi-lang-int8-2025-04-02
|
||||||
|
fi
|
||||||
|
|
||||||
|
dotnet run \
|
||||||
|
--tokens=./sherpa-onnx-dolphin-base-ctc-multi-lang-int8-2025-04-02/tokens.txt \
|
||||||
|
--dolphin-model=./sherpa-onnx-dolphin-base-ctc-multi-lang-int8-2025-04-02/model.int8.onnx \
|
||||||
|
--num-threads=1 \
|
||||||
|
--files ./sherpa-onnx-dolphin-base-ctc-multi-lang-int8-2025-04-02/test_wavs/0.wav
|
||||||
17
scripts/dotnet/OfflineDolphinModelConfig.cs
Normal file
17
scripts/dotnet/OfflineDolphinModelConfig.cs
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
/// Copyright (c) 2025 Xiaomi Corporation (authors: Fangjun Kuang)
|
||||||
|
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
namespace SherpaOnnx
|
||||||
|
{
|
||||||
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
|
public struct OfflineDolphinModelConfig
|
||||||
|
{
|
||||||
|
public OfflineDolphinModelConfig()
|
||||||
|
{
|
||||||
|
Model = "";
|
||||||
|
}
|
||||||
|
[MarshalAs(UnmanagedType.LPStr)]
|
||||||
|
public string Model;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -26,6 +26,7 @@ namespace SherpaOnnx
|
|||||||
SenseVoice = new OfflineSenseVoiceModelConfig();
|
SenseVoice = new OfflineSenseVoiceModelConfig();
|
||||||
Moonshine = new OfflineMoonshineModelConfig();
|
Moonshine = new OfflineMoonshineModelConfig();
|
||||||
FireRedAsr = new OfflineFireRedAsrModelConfig();
|
FireRedAsr = new OfflineFireRedAsrModelConfig();
|
||||||
|
Dolphin = new OfflineDolphinModelConfig();
|
||||||
}
|
}
|
||||||
public OfflineTransducerModelConfig Transducer;
|
public OfflineTransducerModelConfig Transducer;
|
||||||
public OfflineParaformerModelConfig Paraformer;
|
public OfflineParaformerModelConfig Paraformer;
|
||||||
@@ -58,5 +59,6 @@ namespace SherpaOnnx
|
|||||||
public OfflineSenseVoiceModelConfig SenseVoice;
|
public OfflineSenseVoiceModelConfig SenseVoice;
|
||||||
public OfflineMoonshineModelConfig Moonshine;
|
public OfflineMoonshineModelConfig Moonshine;
|
||||||
public OfflineFireRedAsrModelConfig FireRedAsr;
|
public OfflineFireRedAsrModelConfig FireRedAsr;
|
||||||
|
public OfflineDolphinModelConfig Dolphin;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user