mirror of
https://github.com/k2-fsa/sherpa-onnx.git
synced 2026-01-09 07:41:06 +08:00
Add C# API for ten-vad (#2385)
This commit is contained in:
parent
0b8ce73dbf
commit
71aea2f19c
12
.github/scripts/test-dot-net.sh
vendored
12
.github/scripts/test-dot-net.sh
vendored
@ -1,11 +1,20 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -ex
|
||||
|
||||
cd dotnet-examples/
|
||||
|
||||
cd ./version-test
|
||||
./run.sh
|
||||
ls -lh
|
||||
|
||||
cd ../vad-non-streaming-asr-paraformer
|
||||
./run-ten-vad.sh
|
||||
rm -fv *.onnx
|
||||
|
||||
./run.sh
|
||||
rm -fv *.onnx
|
||||
|
||||
cd ../non-streaming-canary-decode-files
|
||||
./run.sh
|
||||
ls -lh
|
||||
@ -106,9 +115,6 @@ rm -rf sherpa-onnx-*
|
||||
./run-paraformer.sh
|
||||
rm -rf sherpa-onnx-*
|
||||
|
||||
cd ../vad-non-streaming-asr-paraformer
|
||||
./run.sh
|
||||
|
||||
cd ../offline-punctuation
|
||||
./run.sh
|
||||
rm -rf sherpa-onnx-*
|
||||
|
||||
4
.github/workflows/test-dot-net.yaml
vendored
4
.github/workflows/test-dot-net.yaml
vendored
@ -102,6 +102,7 @@ jobs:
|
||||
df -h
|
||||
|
||||
- name: Free space
|
||||
if: false
|
||||
shell: bash
|
||||
run: |
|
||||
df -h
|
||||
@ -109,6 +110,7 @@ jobs:
|
||||
df -h
|
||||
|
||||
- name: Free more space
|
||||
if: false
|
||||
shell: bash
|
||||
run: |
|
||||
# https://github.com/orgs/community/discussions/25678
|
||||
@ -120,6 +122,7 @@ jobs:
|
||||
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
|
||||
|
||||
- name: Free Disk Space (Ubuntu)
|
||||
if: false
|
||||
uses: jlumbroso/free-disk-space@main
|
||||
with:
|
||||
# this might remove tools that are actually needed,
|
||||
@ -136,6 +139,7 @@ jobs:
|
||||
swap-storage: true
|
||||
|
||||
- name: Check space
|
||||
if: false
|
||||
shell: bash
|
||||
run: |
|
||||
df -h
|
||||
|
||||
@ -1,8 +1,10 @@
|
||||
// Copyright (c) 2024 Xiaomi Corporation
|
||||
//
|
||||
// This file shows how to use a silero_vad model with a non-streaming Paraformer
|
||||
// for speech recognition.
|
||||
// This file shows how to use a silero_vad model or ten-vad model
|
||||
// with a non-streaming Paraformer for speech recognition.
|
||||
using SherpaOnnx;
|
||||
using System.IO;
|
||||
|
||||
|
||||
class VadNonStreamingAsrParaformer
|
||||
{
|
||||
@ -17,7 +19,31 @@ class VadNonStreamingAsrParaformer
|
||||
var recognizer = new OfflineRecognizer(config);
|
||||
|
||||
var vadModelConfig = new VadModelConfig();
|
||||
vadModelConfig.SileroVad.Model = "./silero_vad.onnx";
|
||||
if (File.Exists("./silero_vad.onnx"))
|
||||
{
|
||||
Console.WriteLine("Use silero-vad");
|
||||
vadModelConfig.SileroVad.Model = "./silero_vad.onnx";
|
||||
vadModelConfig.SileroVad.Threshold = 0.3F;
|
||||
vadModelConfig.SileroVad.MinSilenceDuration = 0.5F;
|
||||
vadModelConfig.SileroVad.MinSpeechDuration = 0.25F;
|
||||
vadModelConfig.SileroVad.MaxSpeechDuration = 5.0F;
|
||||
vadModelConfig.SileroVad.WindowSize = 512;
|
||||
}
|
||||
else if (File.Exists("./ten-vad.onnx"))
|
||||
{
|
||||
Console.WriteLine("Use ten-vad");
|
||||
vadModelConfig.TenVad.Model = "./ten-vad.onnx";
|
||||
vadModelConfig.TenVad.Threshold = 0.3F;
|
||||
vadModelConfig.TenVad.MinSilenceDuration = 0.5F;
|
||||
vadModelConfig.TenVad.MinSpeechDuration = 0.25F;
|
||||
vadModelConfig.TenVad.MaxSpeechDuration = 5.0F;
|
||||
vadModelConfig.TenVad.WindowSize = 256;
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Please download ./silero_vad.onnx or ./ten-vad.onnx");
|
||||
return;
|
||||
}
|
||||
vadModelConfig.Debug = 0;
|
||||
|
||||
var vad = new VoiceActivityDetector(vadModelConfig, 60);
|
||||
@ -27,6 +53,12 @@ class VadNonStreamingAsrParaformer
|
||||
|
||||
int numSamples = reader.Samples.Length;
|
||||
int windowSize = vadModelConfig.SileroVad.WindowSize;
|
||||
|
||||
if (vadModelConfig.TenVad.Model != "")
|
||||
{
|
||||
windowSize = vadModelConfig.TenVad.WindowSize;
|
||||
}
|
||||
|
||||
int sampleRate = vadModelConfig.SampleRate;
|
||||
int numIter = numSamples / windowSize;
|
||||
|
||||
|
||||
20
dotnet-examples/vad-non-streaming-asr-paraformer/run-ten-vad.sh
Executable file
20
dotnet-examples/vad-non-streaming-asr-paraformer/run-ten-vad.sh
Executable file
@ -0,0 +1,20 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -ex
|
||||
|
||||
if [ ! -f ./ten-vad.onnx ]; then
|
||||
curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/ten-vad.onnx
|
||||
fi
|
||||
|
||||
if [ ! -f ./lei-jun-test.wav ]; then
|
||||
curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/lei-jun-test.wav
|
||||
fi
|
||||
|
||||
if [ ! -f ./sherpa-onnx-paraformer-zh-2023-09-14/tokens.txt ]; then
|
||||
curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/sherpa-onnx-paraformer-zh-2023-09-14.tar.bz2
|
||||
|
||||
tar xvf sherpa-onnx-paraformer-zh-2023-09-14.tar.bz2
|
||||
rm sherpa-onnx-paraformer-zh-2023-09-14.tar.bz2
|
||||
fi
|
||||
|
||||
dotnet run
|
||||
0
dotnet-examples/vad-non-streaming-asr-paraformer/run.sh
Normal file → Executable file
0
dotnet-examples/vad-non-streaming-asr-paraformer/run.sh
Normal file → Executable file
33
scripts/dotnet/TenVadModelConfig.cs
Normal file
33
scripts/dotnet/TenVadModelConfig.cs
Normal file
@ -0,0 +1,33 @@
|
||||
/// Copyright (c) 2025 Xiaomi Corporation (authors: Fangjun Kuang)
|
||||
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace SherpaOnnx
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct TenVadModelConfig
|
||||
{
|
||||
public TenVadModelConfig()
|
||||
{
|
||||
Model = "";
|
||||
Threshold = 0.5F;
|
||||
MinSilenceDuration = 0.5F;
|
||||
MinSpeechDuration = 0.25F;
|
||||
WindowSize = 256;
|
||||
MaxSpeechDuration = 5.0F;
|
||||
}
|
||||
|
||||
[MarshalAs(UnmanagedType.LPStr)]
|
||||
public string Model;
|
||||
|
||||
public float Threshold;
|
||||
|
||||
public float MinSilenceDuration;
|
||||
|
||||
public float MinSpeechDuration;
|
||||
|
||||
public int WindowSize;
|
||||
|
||||
public float MaxSpeechDuration;
|
||||
}
|
||||
}
|
||||
@ -14,6 +14,7 @@ namespace SherpaOnnx
|
||||
NumThreads = 1;
|
||||
Provider = "cpu";
|
||||
Debug = 0;
|
||||
TenVad = new TenVadModelConfig();
|
||||
}
|
||||
|
||||
public SileroVadModelConfig SileroVad;
|
||||
@ -26,6 +27,8 @@ namespace SherpaOnnx
|
||||
public string Provider;
|
||||
|
||||
public int Debug;
|
||||
|
||||
public TenVadModelConfig TenVad;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user