Refactor .Net example project (#1049)

Co-authored-by: 东风破 <birdfishs@163.com>
This commit is contained in:
东风破
2024-06-24 10:10:13 +08:00
committed by GitHub
parent 6b7ced2317
commit 00de2bd00b
77 changed files with 526 additions and 651 deletions

View File

@@ -134,6 +134,7 @@ jobs:
- name: Copy files - name: Copy files
shell: bash shell: bash
run: | run: |
cp -v scripts/dotnet/examples/Common.csproj dotnet-examples/Common/
cp -v scripts/dotnet/examples/offline-tts.csproj dotnet-examples/offline-tts/ cp -v scripts/dotnet/examples/offline-tts.csproj dotnet-examples/offline-tts/
cp -v scripts/dotnet/examples/offline-decode-files.csproj dotnet-examples/offline-decode-files/ cp -v scripts/dotnet/examples/offline-decode-files.csproj dotnet-examples/offline-decode-files/
cp -v scripts/dotnet/examples/online-decode-files.csproj dotnet-examples/online-decode-files/ cp -v scripts/dotnet/examples/online-decode-files.csproj dotnet-examples/online-decode-files/

View File

@@ -1,3 +1,6 @@
bin bin
obj obj
v17
.vs
!*.sh !*.sh
*.vsidx

View File

@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<RestoreSources>/tmp/packages;$(RestoreSources);https://api.nuget.org/v3/index.json</RestoreSources>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.9.1" />
<PackageReference Include="org.k2fsa.sherpa.onnx" Version="1.10.1" />
</ItemGroup>
</Project>

View File

@@ -1,174 +1,174 @@
// Copyright (c) 2023 Xiaomi Corporation (authors: Fangjun Kuang) // Copyright (c) 2023 Xiaomi Corporation (authors: Fangjun Kuang)
using System; using System;
using System.IO; using System.IO;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
namespace SherpaOnnx namespace SherpaOnnx
{ {
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
public struct WaveHeader public struct WaveHeader
{ {
public Int32 ChunkID; public Int32 ChunkID;
public Int32 ChunkSize; public Int32 ChunkSize;
public Int32 Format; public Int32 Format;
public Int32 SubChunk1ID; public Int32 SubChunk1ID;
public Int32 SubChunk1Size; public Int32 SubChunk1Size;
public Int16 AudioFormat; public Int16 AudioFormat;
public Int16 NumChannels; public Int16 NumChannels;
public Int32 SampleRate; public Int32 SampleRate;
public Int32 ByteRate; public Int32 ByteRate;
public Int16 BlockAlign; public Int16 BlockAlign;
public Int16 BitsPerSample; public Int16 BitsPerSample;
public Int32 SubChunk2ID; public Int32 SubChunk2ID;
public Int32 SubChunk2Size; public Int32 SubChunk2Size;
public bool Validate() public bool Validate()
{ {
if (ChunkID != 0x46464952) if (ChunkID != 0x46464952)
{ {
Console.WriteLine($"Invalid chunk ID: 0x{ChunkID:X}. Expect 0x46464952"); Console.WriteLine($"Invalid chunk ID: 0x{ChunkID:X}. Expect 0x46464952");
return false; return false;
} }
// E V A W // E V A W
if (Format != 0x45564157) if (Format != 0x45564157)
{ {
Console.WriteLine($"Invalid format: 0x{Format:X}. Expect 0x45564157"); Console.WriteLine($"Invalid format: 0x{Format:X}. Expect 0x45564157");
return false; return false;
} }
// t m f // t m f
if (SubChunk1ID != 0x20746d66) if (SubChunk1ID != 0x20746d66)
{ {
Console.WriteLine($"Invalid SubChunk1ID: 0x{SubChunk1ID:X}. Expect 0x20746d66"); Console.WriteLine($"Invalid SubChunk1ID: 0x{SubChunk1ID:X}. Expect 0x20746d66");
return false; return false;
} }
if (SubChunk1Size != 16) if (SubChunk1Size != 16)
{ {
Console.WriteLine($"Invalid SubChunk1Size: {SubChunk1Size}. Expect 16"); Console.WriteLine($"Invalid SubChunk1Size: {SubChunk1Size}. Expect 16");
return false; return false;
} }
if (AudioFormat != 1) if (AudioFormat != 1)
{ {
Console.WriteLine($"Invalid AudioFormat: {AudioFormat}. Expect 1"); Console.WriteLine($"Invalid AudioFormat: {AudioFormat}. Expect 1");
return false; return false;
} }
if (NumChannels != 1) if (NumChannels != 1)
{ {
Console.WriteLine($"Invalid NumChannels: {NumChannels}. Expect 1"); Console.WriteLine($"Invalid NumChannels: {NumChannels}. Expect 1");
return false; return false;
} }
if (ByteRate != (SampleRate * NumChannels * BitsPerSample / 8)) if (ByteRate != (SampleRate * NumChannels * BitsPerSample / 8))
{ {
Console.WriteLine($"Invalid byte rate: {ByteRate}."); Console.WriteLine($"Invalid byte rate: {ByteRate}.");
return false; return false;
} }
if (BlockAlign != (NumChannels * BitsPerSample / 8)) if (BlockAlign != (NumChannels * BitsPerSample / 8))
{ {
Console.WriteLine($"Invalid block align: {ByteRate}."); Console.WriteLine($"Invalid block align: {ByteRate}.");
return false; return false;
} }
if (BitsPerSample != 16) if (BitsPerSample != 16)
{ // we support only 16 bits per sample { // we support only 16 bits per sample
Console.WriteLine($"Invalid bits per sample: {BitsPerSample}. Expect 16"); Console.WriteLine($"Invalid bits per sample: {BitsPerSample}. Expect 16");
return false; return false;
} }
return true; return true;
} }
} }
// It supports only 16-bit, single channel WAVE format. // It supports only 16-bit, single channel WAVE format.
// The sample rate can be any value. // The sample rate can be any value.
public class WaveReader public class WaveReader
{ {
public WaveReader(String fileName) public WaveReader(String fileName)
{ {
if (!File.Exists(fileName)) if (!File.Exists(fileName))
{ {
throw new ApplicationException($"{fileName} does not exist!"); throw new ApplicationException($"{fileName} does not exist!");
} }
using (var stream = File.Open(fileName, FileMode.Open)) using (var stream = File.Open(fileName, FileMode.Open))
{ {
using (var reader = new BinaryReader(stream)) using (var reader = new BinaryReader(stream))
{ {
_header = ReadHeader(reader); _header = ReadHeader(reader);
if (!_header.Validate()) if (!_header.Validate())
{ {
throw new ApplicationException($"Invalid wave file ${fileName}"); throw new ApplicationException($"Invalid wave file ${fileName}");
} }
SkipMetaData(reader); SkipMetaData(reader);
// now read samples // now read samples
// _header.SubChunk2Size contains number of bytes in total. // _header.SubChunk2Size contains number of bytes in total.
// we assume each sample is of type int16 // we assume each sample is of type int16
byte[] buffer = reader.ReadBytes(_header.SubChunk2Size); byte[] buffer = reader.ReadBytes(_header.SubChunk2Size);
short[] samples_int16 = new short[_header.SubChunk2Size / 2]; short[] samples_int16 = new short[_header.SubChunk2Size / 2];
Buffer.BlockCopy(buffer, 0, samples_int16, 0, buffer.Length); Buffer.BlockCopy(buffer, 0, samples_int16, 0, buffer.Length);
_samples = new float[samples_int16.Length]; _samples = new float[samples_int16.Length];
for (var i = 0; i < samples_int16.Length; ++i) for (var i = 0; i < samples_int16.Length; ++i)
{ {
_samples[i] = samples_int16[i] / 32768.0F; _samples[i] = samples_int16[i] / 32768.0F;
} }
} }
} }
} }
private static WaveHeader ReadHeader(BinaryReader reader) private static WaveHeader ReadHeader(BinaryReader reader)
{ {
byte[] bytes = reader.ReadBytes(Marshal.SizeOf(typeof(WaveHeader))); byte[] bytes = reader.ReadBytes(Marshal.SizeOf(typeof(WaveHeader)));
GCHandle handle = GCHandle.Alloc(bytes, GCHandleType.Pinned); GCHandle handle = GCHandle.Alloc(bytes, GCHandleType.Pinned);
WaveHeader header = (WaveHeader)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(WaveHeader))!; WaveHeader header = (WaveHeader)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(WaveHeader))!;
handle.Free(); handle.Free();
return header; return header;
} }
private void SkipMetaData(BinaryReader reader) private void SkipMetaData(BinaryReader reader)
{ {
var bs = reader.BaseStream; var bs = reader.BaseStream;
Int32 subChunk2ID = _header.SubChunk2ID; Int32 subChunk2ID = _header.SubChunk2ID;
Int32 subChunk2Size = _header.SubChunk2Size; Int32 subChunk2Size = _header.SubChunk2Size;
while (bs.Position != bs.Length && subChunk2ID != 0x61746164) while (bs.Position != bs.Length && subChunk2ID != 0x61746164)
{ {
bs.Seek(subChunk2Size, SeekOrigin.Current); bs.Seek(subChunk2Size, SeekOrigin.Current);
subChunk2ID = reader.ReadInt32(); subChunk2ID = reader.ReadInt32();
subChunk2Size = reader.ReadInt32(); subChunk2Size = reader.ReadInt32();
} }
_header.SubChunk2ID = subChunk2ID; _header.SubChunk2ID = subChunk2ID;
_header.SubChunk2Size = subChunk2Size; _header.SubChunk2Size = subChunk2Size;
} }
private WaveHeader _header; private WaveHeader _header;
// Samples are normalized to the range [-1, 1] // Samples are normalized to the range [-1, 1]
private float[] _samples; private float[] _samples;
public int SampleRate => _header.SampleRate; public int SampleRate => _header.SampleRate;
public float[] Samples => _samples; public float[] Samples => _samples;
public static void Test(String fileName) public static void Test(String fileName)
{ {
WaveReader reader = new WaveReader(fileName); WaveReader reader = new WaveReader(fileName);
Console.WriteLine($"samples length: {reader.Samples.Length}"); Console.WriteLine($"samples length: {reader.Samples.Length}");
Console.WriteLine($"samples rate: {reader.SampleRate}"); Console.WriteLine($"samples rate: {reader.SampleRate}");
} }
} }
} }

View File

@@ -1 +0,0 @@
../online-decode-files/WaveReader.cs

View File

@@ -9,8 +9,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.9.1" /> <ProjectReference Include="..\Common\Common.csproj" />
<PackageReference Include="org.k2fsa.sherpa.onnx" Version="*" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@@ -1,43 +1,43 @@
// Copyright (c) 2024 Xiaomi Corporation // Copyright (c) 2024 Xiaomi Corporation
// //
// This file shows how to add punctuations to text. // This file shows how to add punctuations to text.
// //
// 1. Download a model from // 1. Download a model from
// https://github.com/k2-fsa/sherpa-onnx/releases/tag/punctuation-models // https://github.com/k2-fsa/sherpa-onnx/releases/tag/punctuation-models
// //
// wget https://github.com/k2-fsa/sherpa-onnx/releases/download/punctuation-models/sherpa-onnx-punct-ct-transformer-zh-en-vocab272727-2024-04-12.tar.bz2 // wget https://github.com/k2-fsa/sherpa-onnx/releases/download/punctuation-models/sherpa-onnx-punct-ct-transformer-zh-en-vocab272727-2024-04-12.tar.bz2
// //
// 3. Now run it // 3. Now run it
// //
// dotnet run // dotnet run
using SherpaOnnx; using SherpaOnnx;
using System.Collections.Generic; using System.Collections.Generic;
using System; using System;
class OfflinePunctuationDemo class OfflinePunctuationDemo
{ {
static void Main(string[] args) static void Main(string[] args)
{ {
var config = new OfflinePunctuationConfig(); var config = new OfflinePunctuationConfig();
config.Model.CtTransformer = "./sherpa-onnx-punct-ct-transformer-zh-en-vocab272727-2024-04-12/model.onnx"; config.Model.CtTransformer = "./sherpa-onnx-punct-ct-transformer-zh-en-vocab272727-2024-04-12/model.onnx";
config.Model.Debug = 1; config.Model.Debug = 1;
config.Model.NumThreads = 1; config.Model.NumThreads = 1;
var punct = new OfflinePunctuation(config); var punct = new OfflinePunctuation(config);
string[] textList = new string[] { string[] textList = new string[] {
"这是一个测试你好吗How are you我很好thank you are you ok谢谢你", "这是一个测试你好吗How are you我很好thank you are you ok谢谢你",
"我们都是木头人不会说话不会动", "我们都是木头人不会说话不会动",
"The African blogosphere is rapidly expanding bringing more voices online in the form of commentaries opinions analyses rants and poetry", "The African blogosphere is rapidly expanding bringing more voices online in the form of commentaries opinions analyses rants and poetry",
}; };
Console.WriteLine("---------"); Console.WriteLine("---------");
foreach (string text in textList) foreach (string text in textList)
{ {
string textWithPunct = punct.AddPunct(text); string textWithPunct = punct.AddPunct(text);
Console.WriteLine("Input text: {0}", text); Console.WriteLine("Input text: {0}", text);
Console.WriteLine("Output text: {0}", textWithPunct); Console.WriteLine("Output text: {0}", textWithPunct);
Console.WriteLine("---------"); Console.WriteLine("---------");
} }
} }
} }

View File

@@ -1,15 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework> <TargetFramework>net6.0</TargetFramework>
<RootNamespace>offline_punctuation</RootNamespace> <RootNamespace>offline_punctuation</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="org.k2fsa.sherpa.onnx" Version="*" /> <ProjectReference Include="..\Common\Common.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

0
dotnet-examples/offline-punctuation/run.sh Executable file → Normal file
View File

View File

@@ -9,9 +9,11 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.9.1" />
<PackageReference Include="org.k2fsa.sherpa.onnx" Version="*" />
<PackageReference Include="PortAudioSharp2" Version="*" /> <PackageReference Include="PortAudioSharp2" Version="*" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Common\Common.csproj" />
</ItemGroup>
</Project> </Project>

View File

@@ -9,8 +9,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.9.1" /> <ProjectReference Include="..\Common\Common.csproj" />
<PackageReference Include="org.k2fsa.sherpa.onnx" Version="*" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@@ -9,8 +9,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.9.1" /> <ProjectReference Include="..\Common\Common.csproj" />
<PackageReference Include="org.k2fsa.sherpa.onnx" Version="*" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@@ -3,34 +3,33 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17 # Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59 VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "online-decode-files", "online-decode-files\online-decode-files.csproj", "{45307474-BECB-4ABE-9388-D01D55A1A9BE}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "online-decode-files", "online-decode-files\online-decode-files.csproj", "{45307474-BECB-4ABE-9388-D01D55A1A9BE}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "offline-decode-files", "offline-decode-files\offline-decode-files.csproj", "{2DAB152C-9E24-47A0-9DB0-781297ECE458}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "offline-decode-files", "offline-decode-files\offline-decode-files.csproj", "{2DAB152C-9E24-47A0-9DB0-781297ECE458}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "speech-recognition-from-microphone", "speech-recognition-from-microphone\speech-recognition-from-microphone.csproj", "{FE4EA1FF-062A-46B3-B78D-C828FED7B82E}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "speech-recognition-from-microphone", "speech-recognition-from-microphone\speech-recognition-from-microphone.csproj", "{FE4EA1FF-062A-46B3-B78D-C828FED7B82E}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "offline-tts", "offline-tts\offline-tts.csproj", "{72196886-7143-4043-96E2-BCACEC6C79EB}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "offline-tts", "offline-tts\offline-tts.csproj", "{72196886-7143-4043-96E2-BCACEC6C79EB}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "offline-tts-play", "offline-tts-play\offline-tts-play.csproj", "{40781464-5948-462B-BA4B-98932711513F}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "offline-tts-play", "offline-tts-play\offline-tts-play.csproj", "{40781464-5948-462B-BA4B-98932711513F}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "spoken-language-identification", "spoken-language-identification\spoken-language-identification.csproj", "{3D7CF3D6-AC45-4D50-9619-5687B1443E94}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "spoken-language-identification", "spoken-language-identification\spoken-language-identification.csproj", "{3D7CF3D6-AC45-4D50-9619-5687B1443E94}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "streaming-hlg-decoding", "streaming-hlg-decoding\streaming-hlg-decoding.csproj", "{C4A368A5-FCA0-419D-97C9-C8CE0B08EB99}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "streaming-hlg-decoding", "streaming-hlg-decoding\streaming-hlg-decoding.csproj", "{C4A368A5-FCA0-419D-97C9-C8CE0B08EB99}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "speaker-identification", "speaker-identification\speaker-identification.csproj", "{2B1B140E-A92F-426B-B0DF-5D916B67304F}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "speaker-identification", "speaker-identification\speaker-identification.csproj", "{2B1B140E-A92F-426B-B0DF-5D916B67304F}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "offline-punctuation", "offline-punctuation\offline-punctuation.csproj", "{42D85582-BB63-4259-A4EA-837D66AC078B}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "offline-punctuation", "offline-punctuation\offline-punctuation.csproj", "{42D85582-BB63-4259-A4EA-837D66AC078B}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "vad-non-streaming-asr-paraformer", "vad-non-streaming-asr-paraformer\vad-non-streaming-asr-paraformer.csproj", "{8CD6B7E5-F59F-47B3-BB87-2B2E3678924D}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "vad-non-streaming-asr-paraformer", "vad-non-streaming-asr-paraformer\vad-non-streaming-asr-paraformer.csproj", "{8CD6B7E5-F59F-47B3-BB87-2B2E3678924D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Common", "Common\Common.csproj", "{401E963F-E25A-43CE-987D-8DB2D4715756}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU Release|Any CPU = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution GlobalSection(ProjectConfigurationPlatforms) = postSolution
{45307474-BECB-4ABE-9388-D01D55A1A9BE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {45307474-BECB-4ABE-9388-D01D55A1A9BE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{45307474-BECB-4ABE-9388-D01D55A1A9BE}.Debug|Any CPU.Build.0 = Debug|Any CPU {45307474-BECB-4ABE-9388-D01D55A1A9BE}.Debug|Any CPU.Build.0 = Debug|Any CPU
@@ -72,5 +71,15 @@ Global
{8CD6B7E5-F59F-47B3-BB87-2B2E3678924D}.Debug|Any CPU.Build.0 = Debug|Any CPU {8CD6B7E5-F59F-47B3-BB87-2B2E3678924D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8CD6B7E5-F59F-47B3-BB87-2B2E3678924D}.Release|Any CPU.ActiveCfg = Release|Any CPU {8CD6B7E5-F59F-47B3-BB87-2B2E3678924D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8CD6B7E5-F59F-47B3-BB87-2B2E3678924D}.Release|Any CPU.Build.0 = Release|Any CPU {8CD6B7E5-F59F-47B3-BB87-2B2E3678924D}.Release|Any CPU.Build.0 = Release|Any CPU
{401E963F-E25A-43CE-987D-8DB2D4715756}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{401E963F-E25A-43CE-987D-8DB2D4715756}.Debug|Any CPU.Build.0 = Debug|Any CPU
{401E963F-E25A-43CE-987D-8DB2D4715756}.Release|Any CPU.ActiveCfg = Release|Any CPU
{401E963F-E25A-43CE-987D-8DB2D4715756}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {07A6023C-0A37-4F82-A29F-896A3A338EAC}
EndGlobalSection EndGlobalSection
EndGlobal EndGlobal

View File

@@ -1 +0,0 @@
../offline-decode-files/WaveReader.cs

View File

@@ -9,7 +9,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="org.k2fsa.sherpa.onnx" Version="*" /> <ProjectReference Include="..\Common\Common.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@@ -9,9 +9,11 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.9.1" />
<PackageReference Include="org.k2fsa.sherpa.onnx" Version="*" />
<PackageReference Include="PortAudioSharp2" Version="*" /> <PackageReference Include="PortAudioSharp2" Version="*" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Common\Common.csproj" />
</ItemGroup>
</Project> </Project>

View File

@@ -1 +0,0 @@
../offline-decode-files/WaveReader.cs

View File

@@ -9,7 +9,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="org.k2fsa.sherpa.onnx" Version="*" /> <ProjectReference Include="..\Common\Common.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@@ -1 +0,0 @@
../online-decode-files/WaveReader.cs

View File

@@ -9,7 +9,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="org.k2fsa.sherpa.onnx" Version="*" /> <ProjectReference Include="..\Common\Common.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@@ -1,62 +1,62 @@
// Copyright (c) 2024 Xiaomi Corporation // Copyright (c) 2024 Xiaomi Corporation
// //
// This file shows how to use a silero_vad model with a non-streaming Paraformer // This file shows how to use a silero_vad model with a non-streaming Paraformer
// for speech recognition. // for speech recognition.
using SherpaOnnx; using SherpaOnnx;
using System.Collections.Generic; using System.Collections.Generic;
using System; using System;
class VadNonStreamingAsrParaformer class VadNonStreamingAsrParaformer
{ {
static void Main(string[] args) static void Main(string[] args)
{ {
// please download model files from // please download model files from
// https://github.com/k2-fsa/sherpa-onnx/releases/tag/asr-models // https://github.com/k2-fsa/sherpa-onnx/releases/tag/asr-models
OfflineRecognizerConfig config = new OfflineRecognizerConfig(); OfflineRecognizerConfig config = new OfflineRecognizerConfig();
config.ModelConfig.Paraformer.Model = "./sherpa-onnx-paraformer-zh-2023-03-28/model.int8.onnx"; config.ModelConfig.Paraformer.Model = "./sherpa-onnx-paraformer-zh-2023-03-28/model.int8.onnx";
config.ModelConfig.Tokens = "./sherpa-onnx-paraformer-zh-2023-03-28/tokens.txt"; config.ModelConfig.Tokens = "./sherpa-onnx-paraformer-zh-2023-03-28/tokens.txt";
config.ModelConfig.Debug = 0; config.ModelConfig.Debug = 0;
OfflineRecognizer recognizer = new OfflineRecognizer(config); OfflineRecognizer recognizer = new OfflineRecognizer(config);
VadModelConfig vadModelConfig = new VadModelConfig(); VadModelConfig vadModelConfig = new VadModelConfig();
vadModelConfig.SileroVad.Model = "./silero_vad.onnx"; vadModelConfig.SileroVad.Model = "./silero_vad.onnx";
vadModelConfig.Debug = 0; vadModelConfig.Debug = 0;
VoiceActivityDetector vad = new VoiceActivityDetector(vadModelConfig, 60); VoiceActivityDetector vad = new VoiceActivityDetector(vadModelConfig, 60);
string testWaveFilename = "./lei-jun-test.wav"; string testWaveFilename = "./lei-jun-test.wav";
WaveReader reader = new WaveReader(testWaveFilename); WaveReader reader = new WaveReader(testWaveFilename);
int numSamples = reader.Samples.Length; int numSamples = reader.Samples.Length;
int windowSize = vadModelConfig.SileroVad.WindowSize; int windowSize = vadModelConfig.SileroVad.WindowSize;
int sampleRate = vadModelConfig.SampleRate; int sampleRate = vadModelConfig.SampleRate;
int numIter = numSamples / windowSize; int numIter = numSamples / windowSize;
for (int i = 0; i != numIter; ++i) { for (int i = 0; i != numIter; ++i) {
int start = i * windowSize; int start = i * windowSize;
float[] samples = new float[windowSize]; float[] samples = new float[windowSize];
Array.Copy(reader.Samples, start, samples, 0, windowSize); Array.Copy(reader.Samples, start, samples, 0, windowSize);
vad.AcceptWaveform(samples); vad.AcceptWaveform(samples);
if (vad.IsSpeechDetected()) { if (vad.IsSpeechDetected()) {
while (!vad.IsEmpty()) { while (!vad.IsEmpty()) {
SpeechSegment segment = vad.Front(); SpeechSegment segment = vad.Front();
float startTime = segment.Start / (float)sampleRate; float startTime = segment.Start / (float)sampleRate;
float duration = segment.Samples.Length / (float)sampleRate; float duration = segment.Samples.Length / (float)sampleRate;
OfflineStream stream = recognizer.CreateStream(); OfflineStream stream = recognizer.CreateStream();
stream.AcceptWaveform(sampleRate, segment.Samples); stream.AcceptWaveform(sampleRate, segment.Samples);
recognizer.Decode(stream); recognizer.Decode(stream);
String text = stream.Result.Text; String text = stream.Result.Text;
if (!String.IsNullOrEmpty(text)) { if (!String.IsNullOrEmpty(text)) {
Console.WriteLine("{0}--{1}: {2}", String.Format("{0:0.00}", startTime), Console.WriteLine("{0}--{1}: {2}", String.Format("{0:0.00}", startTime),
String.Format("{0:0.00}", startTime+duration), text); String.Format("{0:0.00}", startTime+duration), text);
} }
vad.Pop(); vad.Pop();
} }
} }
} }
} }
} }

View File

@@ -1 +0,0 @@
../online-decode-files/WaveReader.cs

View File

View File

@@ -1,15 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework> <TargetFramework>net6.0</TargetFramework>
<RootNamespace>vad_non_streaming_asr_paraformer</RootNamespace> <RootNamespace>vad_non_streaming_asr_paraformer</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="org.k2fsa.sherpa.onnx" Version="*" /> <ProjectReference Include="..\Common\Common.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@@ -1,10 +1,7 @@
/// Copyright (c) 2024 Xiaomi Corporation (authors: Fangjun Kuang) /// Copyright (c) 2024 Xiaomi Corporation (authors: Fangjun Kuang)
using System.Linq;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
using System; using System;
using System.Runtime.InteropServices;
namespace SherpaOnnx namespace SherpaOnnx
{ {

View File

@@ -2,12 +2,6 @@
/// Copyright (c) 2023 by manyeyes /// Copyright (c) 2023 by manyeyes
/// Copyright (c) 2024.5 by 东风破 /// Copyright (c) 2024.5 by 东风破
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System;
namespace SherpaOnnx namespace SherpaOnnx
{ {
internal static class Dll internal static class Dll

View File

@@ -2,11 +2,7 @@
/// Copyright (c) 2023 by manyeyes /// Copyright (c) 2023 by manyeyes
/// Copyright (c) 2024.5 by 东风破 /// Copyright (c) 2024.5 by 东风破
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text;
using System;
namespace SherpaOnnx namespace SherpaOnnx
{ {
@@ -29,4 +25,4 @@ namespace SherpaOnnx
public int FeatureDim; public int FeatureDim;
} }
} }

View File

@@ -1,13 +1,12 @@
/// Copyright (c) 2023 Xiaomi Corporation (authors: Fangjun Kuang)
/// Copyright (c) 2023 by manyeyes
/// Copyright (c) 2024.5 by 东风破 /// Copyright (c) 2024.5 by 东风破
using System.Linq;
using System.Collections.Generic;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text;
using System;
namespace SherpaOnnx namespace SherpaOnnx
{ {
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
public struct OfflineLMConfig public struct OfflineLMConfig
{ {
@@ -21,4 +20,5 @@ namespace SherpaOnnx
public float Scale; public float Scale;
} }
}
}

View File

@@ -1,13 +1,10 @@
/// Copyright (c) 2024.5 by 东风破 /// Copyright (c) 2024.5 by 东风破
using System.Linq;
using System.Collections.Generic;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text;
using System;
namespace SherpaOnnx namespace SherpaOnnx
{ {
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
public struct OfflineModelConfig public struct OfflineModelConfig
{ {
@@ -55,4 +52,6 @@ namespace SherpaOnnx
[MarshalAs(UnmanagedType.LPStr)] [MarshalAs(UnmanagedType.LPStr)]
public string TeleSpeechCtc; public string TeleSpeechCtc;
} }
}
}

View File

@@ -1,13 +1,12 @@
/// Copyright (c) 2023 Xiaomi Corporation (authors: Fangjun Kuang)
/// Copyright (c) 2023 by manyeyes
/// Copyright (c) 2024.5 by 东风破 /// Copyright (c) 2024.5 by 东风破
using System.Linq;
using System.Collections.Generic;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text;
using System;
namespace SherpaOnnx namespace SherpaOnnx
{ {
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
public struct OfflineNemoEncDecCtcModelConfig public struct OfflineNemoEncDecCtcModelConfig
{ {
@@ -18,4 +17,4 @@ namespace SherpaOnnx
[MarshalAs(UnmanagedType.LPStr)] [MarshalAs(UnmanagedType.LPStr)]
public string Model; public string Model;
} }
} }

View File

@@ -1,10 +1,6 @@
/// Copyright (c) 2024.5 by 东风破 /// Copyright (c) 2024.5 by 东风破
using System.Linq;
using System.Collections.Generic;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text;
using System;
namespace SherpaOnnx namespace SherpaOnnx
{ {
@@ -18,4 +14,5 @@ namespace SherpaOnnx
[MarshalAs(UnmanagedType.LPStr)] [MarshalAs(UnmanagedType.LPStr)]
public string Model; public string Model;
} }
}
}

View File

@@ -1,10 +1,8 @@
/// Copyright (c) 2024 Xiaomi Corporation (authors: Fangjun Kuang) /// Copyright (c) 2024 Xiaomi Corporation (authors: Fangjun Kuang)
using System;
using System.Linq;
using System.Collections.Generic;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text; using System.Text;
using System;
namespace SherpaOnnx namespace SherpaOnnx
{ {

View File

@@ -1,10 +1,6 @@
/// Copyright (c) 2024 Xiaomi Corporation (authors: Fangjun Kuang) /// Copyright (c) 2024 Xiaomi Corporation (authors: Fangjun Kuang)
using System.Linq;
using System.Collections.Generic;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text;
using System;
namespace SherpaOnnx namespace SherpaOnnx
{ {

View File

@@ -1,10 +1,6 @@
/// Copyright (c) 2024 Xiaomi Corporation (authors: Fangjun Kuang) /// Copyright (c) 2024 Xiaomi Corporation (authors: Fangjun Kuang)
using System.Linq;
using System.Collections.Generic;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text;
using System;
namespace SherpaOnnx namespace SherpaOnnx
{ {

View File

@@ -1,10 +1,9 @@
/// Copyright (c) 2024.5 by 东风破 /// Copyright (c) 2024.5 by 东风破
using System.Linq;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
using System; using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
namespace SherpaOnnx namespace SherpaOnnx
{ {
@@ -72,4 +71,5 @@ namespace SherpaOnnx
[DllImport(Dll.Filename, EntryPoint = "DecodeMultipleOfflineStreams")] [DllImport(Dll.Filename, EntryPoint = "DecodeMultipleOfflineStreams")]
private static extern void Decode(IntPtr handle, IntPtr[] streams, int n); private static extern void Decode(IntPtr handle, IntPtr[] streams, int n);
} }
} }

View File

@@ -1,13 +1,10 @@
/// Copyright (c) 2024.5 by 东风破 /// Copyright (c) 2024.5 by 东风破
using System.Linq;
using System.Collections.Generic;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text;
using System;
namespace SherpaOnnx namespace SherpaOnnx
{ {
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
public struct OfflineRecognizerConfig public struct OfflineRecognizerConfig
{ {
@@ -44,4 +41,6 @@ namespace SherpaOnnx
[MarshalAs(UnmanagedType.LPStr)] [MarshalAs(UnmanagedType.LPStr)]
public string RuleFars; public string RuleFars;
} }
}
}

View File

@@ -1,13 +1,12 @@
/// Copyright (c) 2024.5 by 东风破 /// Copyright (c) 2024.5 by 东风破
using System.Linq; using System;
using System.Collections.Generic;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text; using System.Text;
using System;
namespace SherpaOnnx namespace SherpaOnnx
{ {
public class OfflineRecognizerResult public class OfflineRecognizerResult
{ {
public OfflineRecognizerResult(IntPtr handle) public OfflineRecognizerResult(IntPtr handle)
@@ -43,4 +42,6 @@ namespace SherpaOnnx
private String _text; private String _text;
public String Text => _text; public String Text => _text;
} }
} }

View File

@@ -1,13 +1,11 @@
/// Copyright (c) 2024.5 by 东风破 /// Copyright (c) 2024.5 by 东风破
using System.Linq;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
using System; using System;
using System.Runtime.InteropServices;
namespace SherpaOnnx namespace SherpaOnnx
{ {
public class OfflineStream : IDisposable public class OfflineStream : IDisposable
{ {
public OfflineStream(IntPtr p) public OfflineStream(IntPtr p)
@@ -67,4 +65,5 @@ namespace SherpaOnnx
[DllImport(Dll.Filename, EntryPoint = "DestroyOfflineRecognizerResult")] [DllImport(Dll.Filename, EntryPoint = "DestroyOfflineRecognizerResult")]
private static extern void DestroyResult(IntPtr handle); private static extern void DestroyResult(IntPtr handle);
} }
} }

View File

@@ -1,10 +1,6 @@
/// Copyright (c) 2024.5 by 东风破 /// Copyright (c) 2024.5 by 东风破
using System.Linq;
using System.Collections.Generic;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text;
using System;
namespace SherpaOnnx namespace SherpaOnnx
{ {
@@ -18,4 +14,5 @@ namespace SherpaOnnx
[MarshalAs(UnmanagedType.LPStr)] [MarshalAs(UnmanagedType.LPStr)]
public string Model; public string Model;
} }
}
}

View File

@@ -1,10 +1,6 @@
/// Copyright (c) 2024.5 by 东风破 /// Copyright (c) 2024.5 by 东风破
using System.Linq;
using System.Collections.Generic;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text;
using System;
namespace SherpaOnnx namespace SherpaOnnx
{ {
@@ -26,4 +22,5 @@ namespace SherpaOnnx
[MarshalAs(UnmanagedType.LPStr)] [MarshalAs(UnmanagedType.LPStr)]
public string Joiner; public string Joiner;
} }
}
}

View File

@@ -1,10 +1,6 @@
/// Copyright (c) 2024.5 by 东风破 /// Copyright (c) 2024.5 by 东风破
using System.Linq;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
using System; using System;
using System.Runtime.InteropServices;
namespace SherpaOnnx namespace SherpaOnnx
{ {

View File

@@ -1,10 +1,6 @@
/// Copyright (c) 2024.5 by 东风破 /// Copyright (c) 2024.5 by 东风破
using System.Linq;
using System.Collections.Generic;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text;
using System;
namespace SherpaOnnx namespace SherpaOnnx
{ {
@@ -28,4 +24,5 @@ namespace SherpaOnnx
[MarshalAs(UnmanagedType.LPStr)] [MarshalAs(UnmanagedType.LPStr)]
public string RuleFars; public string RuleFars;
} }
}
}

View File

@@ -1,10 +1,6 @@
/// Copyright (c) 2024.5 by 东风破 /// Copyright (c) 2024.5 by 东风破
using System.Linq;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
using System; using System;
using System.Runtime.InteropServices;
namespace SherpaOnnx namespace SherpaOnnx
{ {
@@ -90,4 +86,4 @@ namespace SherpaOnnx
[DllImport(Dll.Filename)] [DllImport(Dll.Filename)]
private static extern int SherpaOnnxWriteWave(IntPtr samples, int n, int sample_rate, [MarshalAs(UnmanagedType.LPStr)] string filename); private static extern int SherpaOnnxWriteWave(IntPtr samples, int n, int sample_rate, [MarshalAs(UnmanagedType.LPStr)] string filename);
} }
} }

View File

@@ -1,13 +1,10 @@
/// Copyright (c) 2024.5 by 东风破 /// Copyright (c) 2024.5 by 东风破
using System.Linq;
using System.Collections.Generic;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text;
using System;
namespace SherpaOnnx namespace SherpaOnnx
{ {
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
public struct OfflineTtsModelConfig public struct OfflineTtsModelConfig
{ {
@@ -25,4 +22,4 @@ namespace SherpaOnnx
[MarshalAs(UnmanagedType.LPStr)] [MarshalAs(UnmanagedType.LPStr)]
public string Provider; public string Provider;
} }
} }

View File

@@ -1,10 +1,6 @@
/// Copyright (c) 2024.5 by 东风破 /// Copyright (c) 2024.5 by 东风破
using System.Linq;
using System.Collections.Generic;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text;
using System;
namespace SherpaOnnx namespace SherpaOnnx
{ {

View File

@@ -1,10 +1,6 @@
/// Copyright (c) 2024.5 by 东风破 /// Copyright (c) 2024.5 by 东风破
using System.Linq;
using System.Collections.Generic;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text;
using System;
namespace SherpaOnnx namespace SherpaOnnx
{ {
@@ -33,4 +29,5 @@ namespace SherpaOnnx
public int TailPaddings; public int TailPaddings;
} }
}
}

View File

@@ -2,11 +2,7 @@
/// Copyright (c) 2023 by manyeyes /// Copyright (c) 2023 by manyeyes
/// Copyright (c) 2024.5 by 东风破 /// Copyright (c) 2024.5 by 东风破
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text;
using System;
namespace SherpaOnnx namespace SherpaOnnx
{ {
@@ -24,4 +20,5 @@ namespace SherpaOnnx
public int MaxActive; public int MaxActive;
} }
}
}

View File

@@ -2,14 +2,11 @@
/// Copyright (c) 2023 by manyeyes /// Copyright (c) 2023 by manyeyes
/// Copyright (c) 2024.5 by 东风破 /// Copyright (c) 2024.5 by 东风破
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text;
using System;
namespace SherpaOnnx namespace SherpaOnnx
{ {
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
public struct OnlineModelConfig public struct OnlineModelConfig
{ {
@@ -52,4 +49,5 @@ namespace SherpaOnnx
[MarshalAs(UnmanagedType.LPStr)] [MarshalAs(UnmanagedType.LPStr)]
public string BpeVocab; public string BpeVocab;
} }
}
}

View File

@@ -2,14 +2,11 @@
/// Copyright (c) 2023 by manyeyes /// Copyright (c) 2023 by manyeyes
/// Copyright (c) 2024.5 by 东风破 /// Copyright (c) 2024.5 by 东风破
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text;
using System;
namespace SherpaOnnx namespace SherpaOnnx
{ {
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
public struct OnlineParaformerModelConfig public struct OnlineParaformerModelConfig
{ {
@@ -25,4 +22,5 @@ namespace SherpaOnnx
[MarshalAs(UnmanagedType.LPStr)] [MarshalAs(UnmanagedType.LPStr)]
public string Decoder; public string Decoder;
} }
}
}

View File

@@ -1,12 +1,10 @@
/// Copyright (c) 2023 Xiaomi Corporation (authors: Fangjun Kuang) /// Copyright (c) 2023 Xiaomi Corporation (authors: Fangjun Kuang)
/// Copyright (c) 2023 by manyeyes /// Copyright (c) 2023 by manyeyes
/// Copyright (c) 2024.5 by 东风破 /// Copyright (c) 2024.5 by 东风破
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text;
using System;
namespace SherpaOnnx namespace SherpaOnnx
{ {
@@ -122,4 +120,4 @@ namespace SherpaOnnx
[DllImport(Dll.Filename)] [DllImport(Dll.Filename)]
private static extern int IsEndpoint(IntPtr handle, IntPtr stream); private static extern int IsEndpoint(IntPtr handle, IntPtr stream);
} }
} }

View File

@@ -2,14 +2,11 @@
/// Copyright (c) 2023 by manyeyes /// Copyright (c) 2023 by manyeyes
/// Copyright (c) 2024.5 by 东风破 /// Copyright (c) 2024.5 by 东风破
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text;
using System;
namespace SherpaOnnx namespace SherpaOnnx
{ {
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
public struct OnlineRecognizerConfig public struct OnlineRecognizerConfig
{ {
@@ -73,4 +70,5 @@ namespace SherpaOnnx
[MarshalAs(UnmanagedType.LPStr)] [MarshalAs(UnmanagedType.LPStr)]
public string RuleFars; public string RuleFars;
} }
}
}

View File

@@ -1,15 +1,13 @@
/// Copyright (c) 2023 Xiaomi Corporation (authors: Fangjun Kuang) /// Copyright (c) 2023 Xiaomi Corporation (authors: Fangjun Kuang)
/// Copyright (c) 2023 by manyeyes /// Copyright (c) 2023 by manyeyes
/// Copyright (c) 2024.5 by 东风破 /// Copyright (c) 2024.5 by 东风破
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text; using System.Text;
using System;
namespace SherpaOnnx namespace SherpaOnnx
{ {
public class OnlineRecognizerResult public class OnlineRecognizerResult
{ {
public OnlineRecognizerResult(IntPtr handle) public OnlineRecognizerResult(IntPtr handle)

View File

@@ -1,15 +1,12 @@
/// Copyright (c) 2023 Xiaomi Corporation (authors: Fangjun Kuang) /// Copyright (c) 2023 Xiaomi Corporation (authors: Fangjun Kuang)
/// Copyright (c) 2023 by manyeyes /// Copyright (c) 2023 by manyeyes
/// Copyright (c) 2024.5 by 东风破 /// Copyright (c) 2024.5 by 东风破
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System; using System;
using System.Runtime.InteropServices;
namespace SherpaOnnx namespace SherpaOnnx
{ {
public class OnlineStream : IDisposable public class OnlineStream : IDisposable
{ {
public OnlineStream(IntPtr p) public OnlineStream(IntPtr p)
@@ -60,4 +57,5 @@ namespace SherpaOnnx
[DllImport(Dll.Filename)] [DllImport(Dll.Filename)]
private static extern void InputFinished(IntPtr handle); private static extern void InputFinished(IntPtr handle);
} }
} }

View File

@@ -2,14 +2,11 @@
/// Copyright (c) 2023 by manyeyes /// Copyright (c) 2023 by manyeyes
/// Copyright (c) 2024.5 by 东风破 /// Copyright (c) 2024.5 by 东风破
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text;
using System;
namespace SherpaOnnx namespace SherpaOnnx
{ {
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
public struct OnlineTransducerModelConfig public struct OnlineTransducerModelConfig
{ {
@@ -29,4 +26,5 @@ namespace SherpaOnnx
[MarshalAs(UnmanagedType.LPStr)] [MarshalAs(UnmanagedType.LPStr)]
public string Joiner; public string Joiner;
} }
}
}

View File

@@ -2,11 +2,7 @@
/// Copyright (c) 2023 by manyeyes /// Copyright (c) 2023 by manyeyes
/// Copyright (c) 2024.5 by 东风破 /// Copyright (c) 2024.5 by 东风破
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text;
using System;
namespace SherpaOnnx namespace SherpaOnnx
{ {

View File

@@ -1,10 +1,6 @@
/// Copyright (c) 2024 Xiaomi Corporation (authors: Fangjun Kuang) /// Copyright (c) 2024 Xiaomi Corporation (authors: Fangjun Kuang)
using System.Linq;
using System.Collections.Generic;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text;
using System;
namespace SherpaOnnx namespace SherpaOnnx
{ {

View File

@@ -1,10 +1,6 @@
/// Copyright (c) 2024.5 by 东风破 /// Copyright (c) 2024.5 by 东风破
using System.Linq;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
using System; using System;
using System.Runtime.InteropServices;
namespace SherpaOnnx namespace SherpaOnnx
{ {
@@ -93,4 +89,4 @@ namespace SherpaOnnx
private static extern void SherpaOnnxSpeakerEmbeddingExtractorDestroyEmbedding(IntPtr p); private static extern void SherpaOnnxSpeakerEmbeddingExtractorDestroyEmbedding(IntPtr p);
} }
} }

View File

@@ -1,10 +1,6 @@
/// Copyright (c) 2024.5 by 东风破 /// Copyright (c) 2024.5 by 东风破
using System.Linq;
using System.Collections.Generic;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text;
using System;
namespace SherpaOnnx namespace SherpaOnnx
{ {

View File

@@ -1,10 +1,8 @@
/// Copyright (c) 2024.5 by 东风破 /// Copyright (c) 2024.5 by 东风破
using System;
using System.Linq;
using System.Collections.Generic; using System.Collections.Generic;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text; using System.Text;
using System;
namespace SherpaOnnx namespace SherpaOnnx
{ {
@@ -186,4 +184,4 @@ namespace SherpaOnnx
[DllImport(Dll.Filename)] [DllImport(Dll.Filename)]
private static extern void SherpaOnnxSpeakerEmbeddingManagerFreeAllSpeakers(IntPtr names); private static extern void SherpaOnnxSpeakerEmbeddingManagerFreeAllSpeakers(IntPtr names);
} }
} }

View File

@@ -1,17 +1,13 @@
/// Copyright (c) 2024 Xiaomi Corporation (authors: Fangjun Kuang) /// Copyright (c) 2024 Xiaomi Corporation (authors: Fangjun Kuang)
using System.Linq;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
using System; using System;
using System.Runtime.InteropServices;
namespace SherpaOnnx namespace SherpaOnnx
{ {
public class SpeechSegment public class SpeechSegment
{ {
public SpeechSegment(IntPtr handle) public SpeechSegment(IntPtr handle)
{ {
Impl impl = (Impl)Marshal.PtrToStructure(handle, typeof(Impl)); Impl impl = (Impl)Marshal.PtrToStructure(handle, typeof(Impl));
_start = impl.Start; _start = impl.Start;
@@ -28,20 +24,20 @@ namespace SherpaOnnx
} }
} }
} }
} }
public int _start; public int _start;
public int Start => _start; public int Start => _start;
private float[] _samples; private float[] _samples;
public float[] Samples => _samples; public float[] Samples => _samples;
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
struct Impl struct Impl
{ {
public int Start; public int Start;
public IntPtr Samples; public IntPtr Samples;
public int Count; public int Count;
} }
} }
} }

View File

@@ -1,10 +1,6 @@
/// Copyright (c) 2024.5 by 东风破 /// Copyright (c) 2024.5 by 东风破
using System.Linq;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
using System; using System;
using System.Runtime.InteropServices;
namespace SherpaOnnx namespace SherpaOnnx
{ {
@@ -68,4 +64,4 @@ namespace SherpaOnnx
[DllImport(Dll.Filename)] [DllImport(Dll.Filename)]
private static extern void SherpaOnnxDestroySpokenLanguageIdentificationResult(IntPtr handle); private static extern void SherpaOnnxDestroySpokenLanguageIdentificationResult(IntPtr handle);
} }
} }

View File

@@ -1,10 +1,6 @@
/// Copyright (c) 2024.5 by 东风破 /// Copyright (c) 2024.5 by 东风破
using System.Linq;
using System.Collections.Generic;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text;
using System;
namespace SherpaOnnx namespace SherpaOnnx
{ {

View File

@@ -1,10 +1,7 @@
/// Copyright (c) 2024.5 by 东风破 /// Copyright (c) 2024.5 by 东风破
using System;
using System.Linq;
using System.Collections.Generic;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text; using System.Text;
using System;
namespace SherpaOnnx namespace SherpaOnnx
{ {
@@ -43,4 +40,4 @@ namespace SherpaOnnx
private String _lang; private String _lang;
public String Lang => _lang; public String Lang => _lang;
} }
} }

View File

@@ -1,10 +1,6 @@
/// Copyright (c) 2024.5 by 东风破 /// Copyright (c) 2024.5 by 东风破
using System.Linq;
using System.Collections.Generic;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text;
using System;
namespace SherpaOnnx namespace SherpaOnnx
{ {

View File

@@ -1,10 +1,6 @@
/// Copyright (c) 2024 Xiaomi Corporation (authors: Fangjun Kuang) /// Copyright (c) 2024 Xiaomi Corporation (authors: Fangjun Kuang)
using System.Linq;
using System.Collections.Generic;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text;
using System;
namespace SherpaOnnx namespace SherpaOnnx
{ {

View File

@@ -1,10 +1,6 @@
/// Copyright (c) 2024 Xiaomi Corporation (authors: Fangjun Kuang) /// Copyright (c) 2024 Xiaomi Corporation (authors: Fangjun Kuang)
using System.Linq;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
using System; using System;
using System.Runtime.InteropServices;
namespace SherpaOnnx namespace SherpaOnnx
{ {
@@ -112,4 +108,3 @@ namespace SherpaOnnx
} }
} }

View File

@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>.net6</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.9.1" />
<PackageReference Include="org.k2fsa.sherpa.onnx" Version="1.10.1" />
</ItemGroup>
</Project>

View File

@@ -8,13 +8,8 @@
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
</PropertyGroup> </PropertyGroup>
<PropertyGroup>
<RestoreSources>/tmp/packages;$(RestoreSources);https://api.nuget.org/v3/index.json</RestoreSources>
</PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.9.1" /> <ProjectReference Include="..\Common\Common.csproj" />
<PackageReference Include="org.k2fsa.sherpa.onnx" Version="*" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@@ -1,19 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework> <TargetFramework>net6.0</TargetFramework>
<RootNamespace>offline_punctuation</RootNamespace> <RootNamespace>offline_punctuation</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <ItemGroup>
<RestoreSources>/tmp/packages;$(RestoreSources);https://api.nuget.org/v3/index.json</RestoreSources> <ProjectReference Include="..\Common\Common.csproj" />
</PropertyGroup> </ItemGroup>
<ItemGroup> </Project>
<PackageReference Include="org.k2fsa.sherpa.onnx" Version="*" />
</ItemGroup>
</Project>

View File

@@ -8,14 +8,12 @@
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
</PropertyGroup> </PropertyGroup>
<PropertyGroup>
<RestoreSources>/tmp/packages;$(RestoreSources);https://api.nuget.org/v3/index.json</RestoreSources>
</PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.9.1" />
<PackageReference Include="org.k2fsa.sherpa.onnx" Version="*" />
<PackageReference Include="PortAudioSharp2" Version="*" /> <PackageReference Include="PortAudioSharp2" Version="*" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Common\Common.csproj" />
</ItemGroup>
</Project> </Project>

View File

@@ -8,13 +8,8 @@
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
</PropertyGroup> </PropertyGroup>
<PropertyGroup>
<RestoreSources>/tmp/packages;$(RestoreSources);https://api.nuget.org/v3/index.json</RestoreSources>
</PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.9.1" /> <ProjectReference Include="..\Common\Common.csproj" />
<PackageReference Include="org.k2fsa.sherpa.onnx" Version="*" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@@ -8,14 +8,8 @@
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
</PropertyGroup> </PropertyGroup>
<PropertyGroup>
<RestoreSources>/tmp/packages;$(RestoreSources);https://api.nuget.org/v3/index.json</RestoreSources>
</PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.9.1" /> <ProjectReference Include="..\Common\Common.csproj" />
<PackageReference Include="org.k2fsa.sherpa.onnx" Version="*" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@@ -8,12 +8,8 @@
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
</PropertyGroup> </PropertyGroup>
<PropertyGroup>
<RestoreSources>/tmp/packages;$(RestoreSources);https://api.nuget.org/v3/index.json</RestoreSources>
</PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="org.k2fsa.sherpa.onnx" Version="*" /> <ProjectReference Include="..\Common\Common.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@@ -8,14 +8,12 @@
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
</PropertyGroup> </PropertyGroup>
<PropertyGroup>
<RestoreSources>/tmp/packages;$(RestoreSources);https://api.nuget.org/v3/index.json</RestoreSources>
</PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.9.1" />
<PackageReference Include="org.k2fsa.sherpa.onnx" Version="*" />
<PackageReference Include="PortAudioSharp2" Version="*" /> <PackageReference Include="PortAudioSharp2" Version="*" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Common\Common.csproj" />
</ItemGroup>
</Project> </Project>

View File

@@ -8,12 +8,8 @@
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
</PropertyGroup> </PropertyGroup>
<PropertyGroup>
<RestoreSources>/tmp/packages;$(RestoreSources);https://api.nuget.org/v3/index.json</RestoreSources>
</PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="org.k2fsa.sherpa.onnx" Version="*" /> <ProjectReference Include="..\Common\Common.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@@ -8,12 +8,8 @@
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
</PropertyGroup> </PropertyGroup>
<PropertyGroup>
<RestoreSources>/tmp/packages;$(RestoreSources);https://api.nuget.org/v3/index.json</RestoreSources>
</PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="org.k2fsa.sherpa.onnx" Version="*" /> <ProjectReference Include="..\Common\Common.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@@ -1,19 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework> <TargetFramework>net6.0</TargetFramework>
<RootNamespace>vad_non_streaming_asr_paraformer</RootNamespace> <RootNamespace>vad_non_streaming_asr_paraformer</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <ItemGroup>
<RestoreSources>/tmp/packages;$(RestoreSources);https://api.nuget.org/v3/index.json</RestoreSources> <ProjectReference Include="..\Common\Common.csproj" />
</PropertyGroup> </ItemGroup>
<ItemGroup> </Project>
<PackageReference Include="org.k2fsa.sherpa.onnx" Version="*" />
</ItemGroup>
</Project>