diff --git a/.github/workflows/test-dot-net.yaml b/.github/workflows/test-dot-net.yaml index 55bc8e6a..5d413c41 100644 --- a/.github/workflows/test-dot-net.yaml +++ b/.github/workflows/test-dot-net.yaml @@ -134,6 +134,7 @@ jobs: - name: Copy files shell: bash 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-decode-files.csproj dotnet-examples/offline-decode-files/ cp -v scripts/dotnet/examples/online-decode-files.csproj dotnet-examples/online-decode-files/ diff --git a/dotnet-examples/.gitignore b/dotnet-examples/.gitignore index 8b3f0df8..e8bdd81c 100644 --- a/dotnet-examples/.gitignore +++ b/dotnet-examples/.gitignore @@ -1,3 +1,6 @@ bin obj +v17 +.vs !*.sh +*.vsidx diff --git a/dotnet-examples/Common/Common.csproj b/dotnet-examples/Common/Common.csproj new file mode 100644 index 00000000..66e156da --- /dev/null +++ b/dotnet-examples/Common/Common.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + true + /tmp/packages;$(RestoreSources);https://api.nuget.org/v3/index.json + + + + + + + diff --git a/dotnet-examples/online-decode-files/WaveReader.cs b/dotnet-examples/Common/WaveHeader.cs similarity index 96% rename from dotnet-examples/online-decode-files/WaveReader.cs rename to dotnet-examples/Common/WaveHeader.cs index 1937b179..7d13b355 100644 --- a/dotnet-examples/online-decode-files/WaveReader.cs +++ b/dotnet-examples/Common/WaveHeader.cs @@ -1,174 +1,174 @@ -// Copyright (c) 2023 Xiaomi Corporation (authors: Fangjun Kuang) -using System; -using System.IO; - -using System.Runtime.InteropServices; - -namespace SherpaOnnx -{ - - [StructLayout(LayoutKind.Sequential)] - public struct WaveHeader - { - public Int32 ChunkID; - public Int32 ChunkSize; - public Int32 Format; - public Int32 SubChunk1ID; - public Int32 SubChunk1Size; - public Int16 AudioFormat; - public Int16 NumChannels; - public Int32 SampleRate; - public Int32 ByteRate; - public Int16 BlockAlign; - public Int16 BitsPerSample; - public Int32 SubChunk2ID; - public Int32 SubChunk2Size; - - public bool Validate() - { - if (ChunkID != 0x46464952) - { - Console.WriteLine($"Invalid chunk ID: 0x{ChunkID:X}. Expect 0x46464952"); - return false; - } - - // E V A W - if (Format != 0x45564157) - { - Console.WriteLine($"Invalid format: 0x{Format:X}. Expect 0x45564157"); - return false; - } - - // t m f - if (SubChunk1ID != 0x20746d66) - { - Console.WriteLine($"Invalid SubChunk1ID: 0x{SubChunk1ID:X}. Expect 0x20746d66"); - return false; - } - - if (SubChunk1Size != 16) - { - Console.WriteLine($"Invalid SubChunk1Size: {SubChunk1Size}. Expect 16"); - return false; - } - - if (AudioFormat != 1) - { - Console.WriteLine($"Invalid AudioFormat: {AudioFormat}. Expect 1"); - return false; - } - - if (NumChannels != 1) - { - Console.WriteLine($"Invalid NumChannels: {NumChannels}. Expect 1"); - return false; - } - - if (ByteRate != (SampleRate * NumChannels * BitsPerSample / 8)) - { - Console.WriteLine($"Invalid byte rate: {ByteRate}."); - return false; - } - - if (BlockAlign != (NumChannels * BitsPerSample / 8)) - { - Console.WriteLine($"Invalid block align: {ByteRate}."); - return false; - } - - if (BitsPerSample != 16) - { // we support only 16 bits per sample - Console.WriteLine($"Invalid bits per sample: {BitsPerSample}. Expect 16"); - return false; - } - - return true; - } - } - - // It supports only 16-bit, single channel WAVE format. - // The sample rate can be any value. - public class WaveReader - { - public WaveReader(String fileName) - { - if (!File.Exists(fileName)) - { - throw new ApplicationException($"{fileName} does not exist!"); - } - - using (var stream = File.Open(fileName, FileMode.Open)) - { - using (var reader = new BinaryReader(stream)) - { - _header = ReadHeader(reader); - - if (!_header.Validate()) - { - throw new ApplicationException($"Invalid wave file ${fileName}"); - } - - SkipMetaData(reader); - - // now read samples - // _header.SubChunk2Size contains number of bytes in total. - // we assume each sample is of type int16 - byte[] buffer = reader.ReadBytes(_header.SubChunk2Size); - short[] samples_int16 = new short[_header.SubChunk2Size / 2]; - Buffer.BlockCopy(buffer, 0, samples_int16, 0, buffer.Length); - - _samples = new float[samples_int16.Length]; - - for (var i = 0; i < samples_int16.Length; ++i) - { - _samples[i] = samples_int16[i] / 32768.0F; - } - } - } - } - - private static WaveHeader ReadHeader(BinaryReader reader) - { - byte[] bytes = reader.ReadBytes(Marshal.SizeOf(typeof(WaveHeader))); - - GCHandle handle = GCHandle.Alloc(bytes, GCHandleType.Pinned); - WaveHeader header = (WaveHeader)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(WaveHeader))!; - handle.Free(); - - return header; - } - - private void SkipMetaData(BinaryReader reader) - { - var bs = reader.BaseStream; - - Int32 subChunk2ID = _header.SubChunk2ID; - Int32 subChunk2Size = _header.SubChunk2Size; - - while (bs.Position != bs.Length && subChunk2ID != 0x61746164) - { - bs.Seek(subChunk2Size, SeekOrigin.Current); - subChunk2ID = reader.ReadInt32(); - subChunk2Size = reader.ReadInt32(); - } - _header.SubChunk2ID = subChunk2ID; - _header.SubChunk2Size = subChunk2Size; - } - - private WaveHeader _header; - - // Samples are normalized to the range [-1, 1] - private float[] _samples; - - public int SampleRate => _header.SampleRate; - public float[] Samples => _samples; - - public static void Test(String fileName) - { - WaveReader reader = new WaveReader(fileName); - Console.WriteLine($"samples length: {reader.Samples.Length}"); - Console.WriteLine($"samples rate: {reader.SampleRate}"); - } - } - -} +// Copyright (c) 2023 Xiaomi Corporation (authors: Fangjun Kuang) +using System; +using System.IO; + +using System.Runtime.InteropServices; + +namespace SherpaOnnx +{ + + [StructLayout(LayoutKind.Sequential)] + public struct WaveHeader + { + public Int32 ChunkID; + public Int32 ChunkSize; + public Int32 Format; + public Int32 SubChunk1ID; + public Int32 SubChunk1Size; + public Int16 AudioFormat; + public Int16 NumChannels; + public Int32 SampleRate; + public Int32 ByteRate; + public Int16 BlockAlign; + public Int16 BitsPerSample; + public Int32 SubChunk2ID; + public Int32 SubChunk2Size; + + public bool Validate() + { + if (ChunkID != 0x46464952) + { + Console.WriteLine($"Invalid chunk ID: 0x{ChunkID:X}. Expect 0x46464952"); + return false; + } + + // E V A W + if (Format != 0x45564157) + { + Console.WriteLine($"Invalid format: 0x{Format:X}. Expect 0x45564157"); + return false; + } + + // t m f + if (SubChunk1ID != 0x20746d66) + { + Console.WriteLine($"Invalid SubChunk1ID: 0x{SubChunk1ID:X}. Expect 0x20746d66"); + return false; + } + + if (SubChunk1Size != 16) + { + Console.WriteLine($"Invalid SubChunk1Size: {SubChunk1Size}. Expect 16"); + return false; + } + + if (AudioFormat != 1) + { + Console.WriteLine($"Invalid AudioFormat: {AudioFormat}. Expect 1"); + return false; + } + + if (NumChannels != 1) + { + Console.WriteLine($"Invalid NumChannels: {NumChannels}. Expect 1"); + return false; + } + + if (ByteRate != (SampleRate * NumChannels * BitsPerSample / 8)) + { + Console.WriteLine($"Invalid byte rate: {ByteRate}."); + return false; + } + + if (BlockAlign != (NumChannels * BitsPerSample / 8)) + { + Console.WriteLine($"Invalid block align: {ByteRate}."); + return false; + } + + if (BitsPerSample != 16) + { // we support only 16 bits per sample + Console.WriteLine($"Invalid bits per sample: {BitsPerSample}. Expect 16"); + return false; + } + + return true; + } + } + + // It supports only 16-bit, single channel WAVE format. + // The sample rate can be any value. + public class WaveReader + { + public WaveReader(String fileName) + { + if (!File.Exists(fileName)) + { + throw new ApplicationException($"{fileName} does not exist!"); + } + + using (var stream = File.Open(fileName, FileMode.Open)) + { + using (var reader = new BinaryReader(stream)) + { + _header = ReadHeader(reader); + + if (!_header.Validate()) + { + throw new ApplicationException($"Invalid wave file ${fileName}"); + } + + SkipMetaData(reader); + + // now read samples + // _header.SubChunk2Size contains number of bytes in total. + // we assume each sample is of type int16 + byte[] buffer = reader.ReadBytes(_header.SubChunk2Size); + short[] samples_int16 = new short[_header.SubChunk2Size / 2]; + Buffer.BlockCopy(buffer, 0, samples_int16, 0, buffer.Length); + + _samples = new float[samples_int16.Length]; + + for (var i = 0; i < samples_int16.Length; ++i) + { + _samples[i] = samples_int16[i] / 32768.0F; + } + } + } + } + + private static WaveHeader ReadHeader(BinaryReader reader) + { + byte[] bytes = reader.ReadBytes(Marshal.SizeOf(typeof(WaveHeader))); + + GCHandle handle = GCHandle.Alloc(bytes, GCHandleType.Pinned); + WaveHeader header = (WaveHeader)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(WaveHeader))!; + handle.Free(); + + return header; + } + + private void SkipMetaData(BinaryReader reader) + { + var bs = reader.BaseStream; + + Int32 subChunk2ID = _header.SubChunk2ID; + Int32 subChunk2Size = _header.SubChunk2Size; + + while (bs.Position != bs.Length && subChunk2ID != 0x61746164) + { + bs.Seek(subChunk2Size, SeekOrigin.Current); + subChunk2ID = reader.ReadInt32(); + subChunk2Size = reader.ReadInt32(); + } + _header.SubChunk2ID = subChunk2ID; + _header.SubChunk2Size = subChunk2Size; + } + + private WaveHeader _header; + + // Samples are normalized to the range [-1, 1] + private float[] _samples; + + public int SampleRate => _header.SampleRate; + public float[] Samples => _samples; + + public static void Test(String fileName) + { + WaveReader reader = new WaveReader(fileName); + Console.WriteLine($"samples length: {reader.Samples.Length}"); + Console.WriteLine($"samples rate: {reader.SampleRate}"); + } + } + +} diff --git a/dotnet-examples/offline-decode-files/WaveReader.cs b/dotnet-examples/offline-decode-files/WaveReader.cs deleted file mode 120000 index bedfc634..00000000 --- a/dotnet-examples/offline-decode-files/WaveReader.cs +++ /dev/null @@ -1 +0,0 @@ -../online-decode-files/WaveReader.cs \ No newline at end of file diff --git a/dotnet-examples/offline-decode-files/offline-decode-files.csproj b/dotnet-examples/offline-decode-files/offline-decode-files.csproj index 336e0349..ffdfb6ac 100644 --- a/dotnet-examples/offline-decode-files/offline-decode-files.csproj +++ b/dotnet-examples/offline-decode-files/offline-decode-files.csproj @@ -9,8 +9,7 @@ - - + diff --git a/dotnet-examples/offline-punctuation/Program.cs b/dotnet-examples/offline-punctuation/Program.cs index d20ff105..d299f8ab 100644 --- a/dotnet-examples/offline-punctuation/Program.cs +++ b/dotnet-examples/offline-punctuation/Program.cs @@ -1,43 +1,43 @@ -// Copyright (c) 2024 Xiaomi Corporation -// -// This file shows how to add punctuations to text. -// -// 1. Download a model from -// 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 -// -// 3. Now run it -// -// dotnet run - -using SherpaOnnx; -using System.Collections.Generic; -using System; - -class OfflinePunctuationDemo -{ - static void Main(string[] args) - { - var config = new OfflinePunctuationConfig(); - config.Model.CtTransformer = "./sherpa-onnx-punct-ct-transformer-zh-en-vocab272727-2024-04-12/model.onnx"; - config.Model.Debug = 1; - config.Model.NumThreads = 1; - var punct = new OfflinePunctuation(config); - - string[] textList = new string[] { - "这是一个测试你好吗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", - }; - - Console.WriteLine("---------"); - foreach (string text in textList) - { - string textWithPunct = punct.AddPunct(text); - Console.WriteLine("Input text: {0}", text); - Console.WriteLine("Output text: {0}", textWithPunct); - Console.WriteLine("---------"); - } - } -} +// Copyright (c) 2024 Xiaomi Corporation +// +// This file shows how to add punctuations to text. +// +// 1. Download a model from +// 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 +// +// 3. Now run it +// +// dotnet run + +using SherpaOnnx; +using System.Collections.Generic; +using System; + +class OfflinePunctuationDemo +{ + static void Main(string[] args) + { + var config = new OfflinePunctuationConfig(); + config.Model.CtTransformer = "./sherpa-onnx-punct-ct-transformer-zh-en-vocab272727-2024-04-12/model.onnx"; + config.Model.Debug = 1; + config.Model.NumThreads = 1; + var punct = new OfflinePunctuation(config); + + string[] textList = new string[] { + "这是一个测试你好吗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", + }; + + Console.WriteLine("---------"); + foreach (string text in textList) + { + string textWithPunct = punct.AddPunct(text); + Console.WriteLine("Input text: {0}", text); + Console.WriteLine("Output text: {0}", textWithPunct); + Console.WriteLine("---------"); + } + } +} diff --git a/dotnet-examples/offline-punctuation/offline-punctuation.csproj b/dotnet-examples/offline-punctuation/offline-punctuation.csproj index 4df05647..2d94fcb3 100644 --- a/dotnet-examples/offline-punctuation/offline-punctuation.csproj +++ b/dotnet-examples/offline-punctuation/offline-punctuation.csproj @@ -1,15 +1,15 @@ - - - - Exe - net6.0 - offline_punctuation - enable - enable - - - - - - - + + + + Exe + net6.0 + offline_punctuation + enable + enable + + + + + + + diff --git a/dotnet-examples/offline-punctuation/run.sh b/dotnet-examples/offline-punctuation/run.sh old mode 100755 new mode 100644 diff --git a/dotnet-examples/offline-tts-play/offline-tts-play.csproj b/dotnet-examples/offline-tts-play/offline-tts-play.csproj index 85caf7e4..d28ae62c 100644 --- a/dotnet-examples/offline-tts-play/offline-tts-play.csproj +++ b/dotnet-examples/offline-tts-play/offline-tts-play.csproj @@ -9,9 +9,11 @@ - - + + + + diff --git a/dotnet-examples/offline-tts/offline-tts.csproj b/dotnet-examples/offline-tts/offline-tts.csproj index 2981ae83..48548fc4 100644 --- a/dotnet-examples/offline-tts/offline-tts.csproj +++ b/dotnet-examples/offline-tts/offline-tts.csproj @@ -9,8 +9,7 @@ - - + diff --git a/dotnet-examples/online-decode-files/online-decode-files.csproj b/dotnet-examples/online-decode-files/online-decode-files.csproj index f3f64089..0ff58110 100644 --- a/dotnet-examples/online-decode-files/online-decode-files.csproj +++ b/dotnet-examples/online-decode-files/online-decode-files.csproj @@ -9,8 +9,7 @@ - - + diff --git a/dotnet-examples/sherpa-onnx.sln b/dotnet-examples/sherpa-onnx.sln index c2685180..d844c503 100644 --- a/dotnet-examples/sherpa-onnx.sln +++ b/dotnet-examples/sherpa-onnx.sln @@ -3,34 +3,33 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.0.31903.59 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 -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 -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 -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 -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 -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 -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 -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 -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 -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 Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Release|Any CPU = Release|Any CPU EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {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 @@ -72,5 +71,15 @@ Global {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.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 EndGlobal diff --git a/dotnet-examples/speaker-identification/WaveReader.cs b/dotnet-examples/speaker-identification/WaveReader.cs deleted file mode 120000 index 2c5d1679..00000000 --- a/dotnet-examples/speaker-identification/WaveReader.cs +++ /dev/null @@ -1 +0,0 @@ -../offline-decode-files/WaveReader.cs \ No newline at end of file diff --git a/dotnet-examples/speaker-identification/speaker-identification.csproj b/dotnet-examples/speaker-identification/speaker-identification.csproj index 3aa481d4..7c857fa5 100644 --- a/dotnet-examples/speaker-identification/speaker-identification.csproj +++ b/dotnet-examples/speaker-identification/speaker-identification.csproj @@ -9,7 +9,7 @@ - + diff --git a/dotnet-examples/speech-recognition-from-microphone/speech-recognition-from-microphone.csproj b/dotnet-examples/speech-recognition-from-microphone/speech-recognition-from-microphone.csproj index 4d7d9056..901c8a15 100644 --- a/dotnet-examples/speech-recognition-from-microphone/speech-recognition-from-microphone.csproj +++ b/dotnet-examples/speech-recognition-from-microphone/speech-recognition-from-microphone.csproj @@ -9,9 +9,11 @@ - - + + + + diff --git a/dotnet-examples/spoken-language-identification/WaveReader.cs b/dotnet-examples/spoken-language-identification/WaveReader.cs deleted file mode 120000 index 2c5d1679..00000000 --- a/dotnet-examples/spoken-language-identification/WaveReader.cs +++ /dev/null @@ -1 +0,0 @@ -../offline-decode-files/WaveReader.cs \ No newline at end of file diff --git a/dotnet-examples/spoken-language-identification/spoken-language-identification.csproj b/dotnet-examples/spoken-language-identification/spoken-language-identification.csproj index eb8b943e..b8b431a4 100644 --- a/dotnet-examples/spoken-language-identification/spoken-language-identification.csproj +++ b/dotnet-examples/spoken-language-identification/spoken-language-identification.csproj @@ -9,7 +9,7 @@ - + diff --git a/dotnet-examples/streaming-hlg-decoding/WaveReader.cs b/dotnet-examples/streaming-hlg-decoding/WaveReader.cs deleted file mode 120000 index bedfc634..00000000 --- a/dotnet-examples/streaming-hlg-decoding/WaveReader.cs +++ /dev/null @@ -1 +0,0 @@ -../online-decode-files/WaveReader.cs \ No newline at end of file diff --git a/dotnet-examples/streaming-hlg-decoding/streaming-hlg-decoding.csproj b/dotnet-examples/streaming-hlg-decoding/streaming-hlg-decoding.csproj index 6030ec85..66e0401f 100644 --- a/dotnet-examples/streaming-hlg-decoding/streaming-hlg-decoding.csproj +++ b/dotnet-examples/streaming-hlg-decoding/streaming-hlg-decoding.csproj @@ -9,7 +9,7 @@ - + diff --git a/dotnet-examples/vad-non-streaming-asr-paraformer/Program.cs b/dotnet-examples/vad-non-streaming-asr-paraformer/Program.cs index 8471c024..13c19f0b 100644 --- a/dotnet-examples/vad-non-streaming-asr-paraformer/Program.cs +++ b/dotnet-examples/vad-non-streaming-asr-paraformer/Program.cs @@ -1,62 +1,62 @@ -// Copyright (c) 2024 Xiaomi Corporation -// -// This file shows how to use a silero_vad model with a non-streaming Paraformer -// for speech recognition. -using SherpaOnnx; -using System.Collections.Generic; -using System; - -class VadNonStreamingAsrParaformer -{ - static void Main(string[] args) - { - // please download model files from - // https://github.com/k2-fsa/sherpa-onnx/releases/tag/asr-models - OfflineRecognizerConfig config = new OfflineRecognizerConfig(); - 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.Debug = 0; - OfflineRecognizer recognizer = new OfflineRecognizer(config); - - VadModelConfig vadModelConfig = new VadModelConfig(); - vadModelConfig.SileroVad.Model = "./silero_vad.onnx"; - vadModelConfig.Debug = 0; - - VoiceActivityDetector vad = new VoiceActivityDetector(vadModelConfig, 60); - - string testWaveFilename = "./lei-jun-test.wav"; - WaveReader reader = new WaveReader(testWaveFilename); - - int numSamples = reader.Samples.Length; - int windowSize = vadModelConfig.SileroVad.WindowSize; - int sampleRate = vadModelConfig.SampleRate; - int numIter = numSamples / windowSize; - - for (int i = 0; i != numIter; ++i) { - int start = i * windowSize; - float[] samples = new float[windowSize]; - Array.Copy(reader.Samples, start, samples, 0, windowSize); - vad.AcceptWaveform(samples); - if (vad.IsSpeechDetected()) { - while (!vad.IsEmpty()) { - SpeechSegment segment = vad.Front(); - float startTime = segment.Start / (float)sampleRate; - float duration = segment.Samples.Length / (float)sampleRate; - - OfflineStream stream = recognizer.CreateStream(); - stream.AcceptWaveform(sampleRate, segment.Samples); - recognizer.Decode(stream); - String text = stream.Result.Text; - - if (!String.IsNullOrEmpty(text)) { - Console.WriteLine("{0}--{1}: {2}", String.Format("{0:0.00}", startTime), - String.Format("{0:0.00}", startTime+duration), text); - } - - vad.Pop(); - } - } - } - } -} - +// Copyright (c) 2024 Xiaomi Corporation +// +// This file shows how to use a silero_vad model with a non-streaming Paraformer +// for speech recognition. +using SherpaOnnx; +using System.Collections.Generic; +using System; + +class VadNonStreamingAsrParaformer +{ + static void Main(string[] args) + { + // please download model files from + // https://github.com/k2-fsa/sherpa-onnx/releases/tag/asr-models + OfflineRecognizerConfig config = new OfflineRecognizerConfig(); + 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.Debug = 0; + OfflineRecognizer recognizer = new OfflineRecognizer(config); + + VadModelConfig vadModelConfig = new VadModelConfig(); + vadModelConfig.SileroVad.Model = "./silero_vad.onnx"; + vadModelConfig.Debug = 0; + + VoiceActivityDetector vad = new VoiceActivityDetector(vadModelConfig, 60); + + string testWaveFilename = "./lei-jun-test.wav"; + WaveReader reader = new WaveReader(testWaveFilename); + + int numSamples = reader.Samples.Length; + int windowSize = vadModelConfig.SileroVad.WindowSize; + int sampleRate = vadModelConfig.SampleRate; + int numIter = numSamples / windowSize; + + for (int i = 0; i != numIter; ++i) { + int start = i * windowSize; + float[] samples = new float[windowSize]; + Array.Copy(reader.Samples, start, samples, 0, windowSize); + vad.AcceptWaveform(samples); + if (vad.IsSpeechDetected()) { + while (!vad.IsEmpty()) { + SpeechSegment segment = vad.Front(); + float startTime = segment.Start / (float)sampleRate; + float duration = segment.Samples.Length / (float)sampleRate; + + OfflineStream stream = recognizer.CreateStream(); + stream.AcceptWaveform(sampleRate, segment.Samples); + recognizer.Decode(stream); + String text = stream.Result.Text; + + if (!String.IsNullOrEmpty(text)) { + Console.WriteLine("{0}--{1}: {2}", String.Format("{0:0.00}", startTime), + String.Format("{0:0.00}", startTime+duration), text); + } + + vad.Pop(); + } + } + } + } +} + diff --git a/dotnet-examples/vad-non-streaming-asr-paraformer/WaveReader.cs b/dotnet-examples/vad-non-streaming-asr-paraformer/WaveReader.cs deleted file mode 120000 index bedfc634..00000000 --- a/dotnet-examples/vad-non-streaming-asr-paraformer/WaveReader.cs +++ /dev/null @@ -1 +0,0 @@ -../online-decode-files/WaveReader.cs \ No newline at end of file diff --git a/dotnet-examples/vad-non-streaming-asr-paraformer/run.sh b/dotnet-examples/vad-non-streaming-asr-paraformer/run.sh old mode 100755 new mode 100644 diff --git a/dotnet-examples/vad-non-streaming-asr-paraformer/vad-non-streaming-asr-paraformer.csproj b/dotnet-examples/vad-non-streaming-asr-paraformer/vad-non-streaming-asr-paraformer.csproj index 3a957bcf..a5c5f102 100644 --- a/dotnet-examples/vad-non-streaming-asr-paraformer/vad-non-streaming-asr-paraformer.csproj +++ b/dotnet-examples/vad-non-streaming-asr-paraformer/vad-non-streaming-asr-paraformer.csproj @@ -1,15 +1,15 @@ - - - - Exe - net6.0 - vad_non_streaming_asr_paraformer - enable - enable - - - - - - - + + + + Exe + net6.0 + vad_non_streaming_asr_paraformer + enable + enable + + + + + + + diff --git a/scripts/dotnet/CircularBuffer.cs b/scripts/dotnet/CircularBuffer.cs index 9a507123..96d8df66 100644 --- a/scripts/dotnet/CircularBuffer.cs +++ b/scripts/dotnet/CircularBuffer.cs @@ -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.Runtime.InteropServices; namespace SherpaOnnx { diff --git a/scripts/dotnet/Dll.cs b/scripts/dotnet/Dll.cs index 3ae93b8b..91317289 100644 --- a/scripts/dotnet/Dll.cs +++ b/scripts/dotnet/Dll.cs @@ -2,12 +2,6 @@ /// Copyright (c) 2023 by manyeyes /// Copyright (c) 2024.5 by 东风破 -using System.Collections.Generic; -using System.Linq; -using System.Runtime.InteropServices; -using System.Text; -using System; - namespace SherpaOnnx { internal static class Dll diff --git a/scripts/dotnet/FeatureConfig.cs b/scripts/dotnet/FeatureConfig.cs index f7bfb97c..b7a79216 100644 --- a/scripts/dotnet/FeatureConfig.cs +++ b/scripts/dotnet/FeatureConfig.cs @@ -2,11 +2,7 @@ /// Copyright (c) 2023 by manyeyes /// Copyright (c) 2024.5 by 东风破 -using System.Collections.Generic; -using System.Linq; using System.Runtime.InteropServices; -using System.Text; -using System; namespace SherpaOnnx { @@ -29,4 +25,4 @@ namespace SherpaOnnx public int FeatureDim; } -} +} \ No newline at end of file diff --git a/scripts/dotnet/OfflineLMConfig.cs b/scripts/dotnet/OfflineLMConfig.cs index 51683a71..6452a038 100644 --- a/scripts/dotnet/OfflineLMConfig.cs +++ b/scripts/dotnet/OfflineLMConfig.cs @@ -1,13 +1,12 @@ +/// Copyright (c) 2023 Xiaomi Corporation (authors: Fangjun Kuang) +/// Copyright (c) 2023 by manyeyes /// Copyright (c) 2024.5 by 东风破 -using System.Linq; -using System.Collections.Generic; using System.Runtime.InteropServices; -using System.Text; -using System; namespace SherpaOnnx { + [StructLayout(LayoutKind.Sequential)] public struct OfflineLMConfig { @@ -21,4 +20,5 @@ namespace SherpaOnnx public float Scale; } -} + +} \ No newline at end of file diff --git a/scripts/dotnet/OfflineModelConfig.cs b/scripts/dotnet/OfflineModelConfig.cs index f5620944..ddb489d4 100644 --- a/scripts/dotnet/OfflineModelConfig.cs +++ b/scripts/dotnet/OfflineModelConfig.cs @@ -1,13 +1,10 @@ /// Copyright (c) 2024.5 by 东风破 -using System.Linq; -using System.Collections.Generic; using System.Runtime.InteropServices; -using System.Text; -using System; namespace SherpaOnnx { + [StructLayout(LayoutKind.Sequential)] public struct OfflineModelConfig { @@ -55,4 +52,6 @@ namespace SherpaOnnx [MarshalAs(UnmanagedType.LPStr)] public string TeleSpeechCtc; } -} + + +} \ No newline at end of file diff --git a/scripts/dotnet/OfflineNemoEncDecCtcModelConfig.cs b/scripts/dotnet/OfflineNemoEncDecCtcModelConfig.cs index 8dbf19d9..18bf5a37 100644 --- a/scripts/dotnet/OfflineNemoEncDecCtcModelConfig.cs +++ b/scripts/dotnet/OfflineNemoEncDecCtcModelConfig.cs @@ -1,13 +1,12 @@ +/// Copyright (c) 2023 Xiaomi Corporation (authors: Fangjun Kuang) +/// Copyright (c) 2023 by manyeyes /// Copyright (c) 2024.5 by 东风破 -using System.Linq; -using System.Collections.Generic; using System.Runtime.InteropServices; -using System.Text; -using System; namespace SherpaOnnx { + [StructLayout(LayoutKind.Sequential)] public struct OfflineNemoEncDecCtcModelConfig { @@ -18,4 +17,4 @@ namespace SherpaOnnx [MarshalAs(UnmanagedType.LPStr)] public string Model; } -} +} \ No newline at end of file diff --git a/scripts/dotnet/OfflineParaformerModelConfig.cs b/scripts/dotnet/OfflineParaformerModelConfig.cs index 6acf194e..ef1cabb6 100644 --- a/scripts/dotnet/OfflineParaformerModelConfig.cs +++ b/scripts/dotnet/OfflineParaformerModelConfig.cs @@ -1,10 +1,6 @@ /// Copyright (c) 2024.5 by 东风破 -using System.Linq; -using System.Collections.Generic; using System.Runtime.InteropServices; -using System.Text; -using System; namespace SherpaOnnx { @@ -18,4 +14,5 @@ namespace SherpaOnnx [MarshalAs(UnmanagedType.LPStr)] public string Model; } -} + +} \ No newline at end of file diff --git a/scripts/dotnet/OfflinePunctuation.cs b/scripts/dotnet/OfflinePunctuation.cs index 9d3c5400..384df045 100644 --- a/scripts/dotnet/OfflinePunctuation.cs +++ b/scripts/dotnet/OfflinePunctuation.cs @@ -1,10 +1,8 @@ -/// Copyright (c) 2024 Xiaomi Corporation (authors: Fangjun Kuang) - -using System.Linq; -using System.Collections.Generic; +/// Copyright (c) 2024 Xiaomi Corporation (authors: Fangjun Kuang) +using System; using System.Runtime.InteropServices; using System.Text; -using System; + namespace SherpaOnnx { diff --git a/scripts/dotnet/OfflinePunctuationConfig.cs b/scripts/dotnet/OfflinePunctuationConfig.cs index 6c503a89..8f4dba45 100644 --- a/scripts/dotnet/OfflinePunctuationConfig.cs +++ b/scripts/dotnet/OfflinePunctuationConfig.cs @@ -1,10 +1,6 @@ /// Copyright (c) 2024 Xiaomi Corporation (authors: Fangjun Kuang) -using System.Linq; -using System.Collections.Generic; using System.Runtime.InteropServices; -using System.Text; -using System; namespace SherpaOnnx { diff --git a/scripts/dotnet/OfflinePunctuationModelConfig.cs b/scripts/dotnet/OfflinePunctuationModelConfig.cs index f7600836..a6a95246 100644 --- a/scripts/dotnet/OfflinePunctuationModelConfig.cs +++ b/scripts/dotnet/OfflinePunctuationModelConfig.cs @@ -1,10 +1,6 @@ /// Copyright (c) 2024 Xiaomi Corporation (authors: Fangjun Kuang) -using System.Linq; -using System.Collections.Generic; using System.Runtime.InteropServices; -using System.Text; -using System; namespace SherpaOnnx { diff --git a/scripts/dotnet/OfflineRecognizer.cs b/scripts/dotnet/OfflineRecognizer.cs index 58268048..1acda5df 100644 --- a/scripts/dotnet/OfflineRecognizer.cs +++ b/scripts/dotnet/OfflineRecognizer.cs @@ -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.Collections.Generic; +using System.Linq; +using System.Runtime.InteropServices; namespace SherpaOnnx { @@ -72,4 +71,5 @@ namespace SherpaOnnx [DllImport(Dll.Filename, EntryPoint = "DecodeMultipleOfflineStreams")] private static extern void Decode(IntPtr handle, IntPtr[] streams, int n); } + } diff --git a/scripts/dotnet/OfflineRecognizerConfig.cs b/scripts/dotnet/OfflineRecognizerConfig.cs index 371a556e..ca1c4d01 100644 --- a/scripts/dotnet/OfflineRecognizerConfig.cs +++ b/scripts/dotnet/OfflineRecognizerConfig.cs @@ -1,13 +1,10 @@ /// Copyright (c) 2024.5 by 东风破 -using System.Linq; -using System.Collections.Generic; using System.Runtime.InteropServices; -using System.Text; -using System; namespace SherpaOnnx { + [StructLayout(LayoutKind.Sequential)] public struct OfflineRecognizerConfig { @@ -44,4 +41,6 @@ namespace SherpaOnnx [MarshalAs(UnmanagedType.LPStr)] public string RuleFars; } -} + + +} \ No newline at end of file diff --git a/scripts/dotnet/OfflineRecognizerResult.cs b/scripts/dotnet/OfflineRecognizerResult.cs index 433d70bc..8c10b6f8 100644 --- a/scripts/dotnet/OfflineRecognizerResult.cs +++ b/scripts/dotnet/OfflineRecognizerResult.cs @@ -1,13 +1,12 @@ -/// Copyright (c) 2024.5 by 东风破 +/// Copyright (c) 2024.5 by 东风破 -using System.Linq; -using System.Collections.Generic; +using System; using System.Runtime.InteropServices; using System.Text; -using System; namespace SherpaOnnx { + public class OfflineRecognizerResult { public OfflineRecognizerResult(IntPtr handle) @@ -43,4 +42,6 @@ namespace SherpaOnnx private String _text; public String Text => _text; } + + } diff --git a/scripts/dotnet/OfflineStream.cs b/scripts/dotnet/OfflineStream.cs index 0a7cafb8..90e48569 100644 --- a/scripts/dotnet/OfflineStream.cs +++ b/scripts/dotnet/OfflineStream.cs @@ -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.Runtime.InteropServices; namespace SherpaOnnx { + public class OfflineStream : IDisposable { public OfflineStream(IntPtr p) @@ -67,4 +65,5 @@ namespace SherpaOnnx [DllImport(Dll.Filename, EntryPoint = "DestroyOfflineRecognizerResult")] private static extern void DestroyResult(IntPtr handle); } + } diff --git a/scripts/dotnet/OfflineTdnnModelConfig.cs b/scripts/dotnet/OfflineTdnnModelConfig.cs index 5a27c0b4..77c3f830 100644 --- a/scripts/dotnet/OfflineTdnnModelConfig.cs +++ b/scripts/dotnet/OfflineTdnnModelConfig.cs @@ -1,10 +1,6 @@ /// Copyright (c) 2024.5 by 东风破 -using System.Linq; -using System.Collections.Generic; using System.Runtime.InteropServices; -using System.Text; -using System; namespace SherpaOnnx { @@ -18,4 +14,5 @@ namespace SherpaOnnx [MarshalAs(UnmanagedType.LPStr)] public string Model; } -} + +} \ No newline at end of file diff --git a/scripts/dotnet/OfflineTransducerModelConfig.cs b/scripts/dotnet/OfflineTransducerModelConfig.cs index 7c10745f..5a215031 100644 --- a/scripts/dotnet/OfflineTransducerModelConfig.cs +++ b/scripts/dotnet/OfflineTransducerModelConfig.cs @@ -1,10 +1,6 @@ /// Copyright (c) 2024.5 by 东风破 -using System.Linq; -using System.Collections.Generic; using System.Runtime.InteropServices; -using System.Text; -using System; namespace SherpaOnnx { @@ -26,4 +22,5 @@ namespace SherpaOnnx [MarshalAs(UnmanagedType.LPStr)] public string Joiner; } -} + +} \ No newline at end of file diff --git a/scripts/dotnet/OfflineTts.cs b/scripts/dotnet/OfflineTts.cs index 1317b132..357a8dd2 100644 --- a/scripts/dotnet/OfflineTts.cs +++ b/scripts/dotnet/OfflineTts.cs @@ -1,10 +1,6 @@ -/// Copyright (c) 2024.5 by 东风破 - -using System.Linq; -using System.Collections.Generic; -using System.Runtime.InteropServices; -using System.Text; +/// Copyright (c) 2024.5 by 东风破 using System; +using System.Runtime.InteropServices; namespace SherpaOnnx { diff --git a/scripts/dotnet/OfflineTtsConfig.cs b/scripts/dotnet/OfflineTtsConfig.cs index c0f49c53..897df0c0 100644 --- a/scripts/dotnet/OfflineTtsConfig.cs +++ b/scripts/dotnet/OfflineTtsConfig.cs @@ -1,10 +1,6 @@ /// Copyright (c) 2024.5 by 东风破 -using System.Linq; -using System.Collections.Generic; using System.Runtime.InteropServices; -using System.Text; -using System; namespace SherpaOnnx { @@ -28,4 +24,5 @@ namespace SherpaOnnx [MarshalAs(UnmanagedType.LPStr)] public string RuleFars; } -} + +} \ No newline at end of file diff --git a/scripts/dotnet/OfflineTtsGeneratedAudio.cs b/scripts/dotnet/OfflineTtsGeneratedAudio.cs index 89f77604..ad7540f5 100644 --- a/scripts/dotnet/OfflineTtsGeneratedAudio.cs +++ b/scripts/dotnet/OfflineTtsGeneratedAudio.cs @@ -1,10 +1,6 @@ -/// Copyright (c) 2024.5 by 东风破 - -using System.Linq; -using System.Collections.Generic; -using System.Runtime.InteropServices; -using System.Text; +/// Copyright (c) 2024.5 by 东风破 using System; +using System.Runtime.InteropServices; namespace SherpaOnnx { @@ -90,4 +86,4 @@ namespace SherpaOnnx [DllImport(Dll.Filename)] private static extern int SherpaOnnxWriteWave(IntPtr samples, int n, int sample_rate, [MarshalAs(UnmanagedType.LPStr)] string filename); } -} \ No newline at end of file +} diff --git a/scripts/dotnet/OfflineTtsModelConfig.cs b/scripts/dotnet/OfflineTtsModelConfig.cs index 50ccb667..40aa6391 100644 --- a/scripts/dotnet/OfflineTtsModelConfig.cs +++ b/scripts/dotnet/OfflineTtsModelConfig.cs @@ -1,13 +1,10 @@ /// Copyright (c) 2024.5 by 东风破 -using System.Linq; -using System.Collections.Generic; using System.Runtime.InteropServices; -using System.Text; -using System; namespace SherpaOnnx { + [StructLayout(LayoutKind.Sequential)] public struct OfflineTtsModelConfig { @@ -25,4 +22,4 @@ namespace SherpaOnnx [MarshalAs(UnmanagedType.LPStr)] public string Provider; } -} +} \ No newline at end of file diff --git a/scripts/dotnet/OfflineTtsVitsModelConfig.cs b/scripts/dotnet/OfflineTtsVitsModelConfig.cs index 820964c8..f72430b2 100644 --- a/scripts/dotnet/OfflineTtsVitsModelConfig.cs +++ b/scripts/dotnet/OfflineTtsVitsModelConfig.cs @@ -1,10 +1,6 @@ /// Copyright (c) 2024.5 by 东风破 -using System.Linq; -using System.Collections.Generic; using System.Runtime.InteropServices; -using System.Text; -using System; namespace SherpaOnnx { diff --git a/scripts/dotnet/OfflineWhisperModelConfig.cs b/scripts/dotnet/OfflineWhisperModelConfig.cs index 91af9979..16b6387c 100644 --- a/scripts/dotnet/OfflineWhisperModelConfig.cs +++ b/scripts/dotnet/OfflineWhisperModelConfig.cs @@ -1,10 +1,6 @@ /// Copyright (c) 2024.5 by 东风破 -using System.Linq; -using System.Collections.Generic; using System.Runtime.InteropServices; -using System.Text; -using System; namespace SherpaOnnx { @@ -33,4 +29,5 @@ namespace SherpaOnnx public int TailPaddings; } -} + +} \ No newline at end of file diff --git a/scripts/dotnet/OnlineCtcFstDecoderConfig.cs b/scripts/dotnet/OnlineCtcFstDecoderConfig.cs index 9669a8cf..9e9e6c8d 100644 --- a/scripts/dotnet/OnlineCtcFstDecoderConfig.cs +++ b/scripts/dotnet/OnlineCtcFstDecoderConfig.cs @@ -2,11 +2,7 @@ /// Copyright (c) 2023 by manyeyes /// Copyright (c) 2024.5 by 东风破 -using System.Collections.Generic; -using System.Linq; using System.Runtime.InteropServices; -using System.Text; -using System; namespace SherpaOnnx { @@ -24,4 +20,5 @@ namespace SherpaOnnx public int MaxActive; } -} + +} \ No newline at end of file diff --git a/scripts/dotnet/OnlineModelConfig.cs b/scripts/dotnet/OnlineModelConfig.cs index dcba23cf..2c7d502e 100644 --- a/scripts/dotnet/OnlineModelConfig.cs +++ b/scripts/dotnet/OnlineModelConfig.cs @@ -2,14 +2,11 @@ /// Copyright (c) 2023 by manyeyes /// Copyright (c) 2024.5 by 东风破 -using System.Collections.Generic; -using System.Linq; using System.Runtime.InteropServices; -using System.Text; -using System; namespace SherpaOnnx { + [StructLayout(LayoutKind.Sequential)] public struct OnlineModelConfig { @@ -52,4 +49,5 @@ namespace SherpaOnnx [MarshalAs(UnmanagedType.LPStr)] public string BpeVocab; } -} + +} \ No newline at end of file diff --git a/scripts/dotnet/OnlineParaformerModelConfig.cs b/scripts/dotnet/OnlineParaformerModelConfig.cs index 0afc6d90..ee3c722b 100644 --- a/scripts/dotnet/OnlineParaformerModelConfig.cs +++ b/scripts/dotnet/OnlineParaformerModelConfig.cs @@ -2,14 +2,11 @@ /// Copyright (c) 2023 by manyeyes /// Copyright (c) 2024.5 by 东风破 -using System.Collections.Generic; -using System.Linq; using System.Runtime.InteropServices; -using System.Text; -using System; namespace SherpaOnnx { + [StructLayout(LayoutKind.Sequential)] public struct OnlineParaformerModelConfig { @@ -25,4 +22,5 @@ namespace SherpaOnnx [MarshalAs(UnmanagedType.LPStr)] public string Decoder; } -} + +} \ No newline at end of file diff --git a/scripts/dotnet/OnlineRecognizer.cs b/scripts/dotnet/OnlineRecognizer.cs index b881798e..f2b7cdea 100644 --- a/scripts/dotnet/OnlineRecognizer.cs +++ b/scripts/dotnet/OnlineRecognizer.cs @@ -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) 2024.5 by 东风破 - +using System; using System.Collections.Generic; using System.Linq; using System.Runtime.InteropServices; -using System.Text; -using System; namespace SherpaOnnx { @@ -122,4 +120,4 @@ namespace SherpaOnnx [DllImport(Dll.Filename)] private static extern int IsEndpoint(IntPtr handle, IntPtr stream); } -} \ No newline at end of file +} diff --git a/scripts/dotnet/OnlineRecognizerConfig.cs b/scripts/dotnet/OnlineRecognizerConfig.cs index dc58fe84..302491c0 100644 --- a/scripts/dotnet/OnlineRecognizerConfig.cs +++ b/scripts/dotnet/OnlineRecognizerConfig.cs @@ -2,14 +2,11 @@ /// Copyright (c) 2023 by manyeyes /// Copyright (c) 2024.5 by 东风破 -using System.Collections.Generic; -using System.Linq; using System.Runtime.InteropServices; -using System.Text; -using System; namespace SherpaOnnx { + [StructLayout(LayoutKind.Sequential)] public struct OnlineRecognizerConfig { @@ -73,4 +70,5 @@ namespace SherpaOnnx [MarshalAs(UnmanagedType.LPStr)] public string RuleFars; } -} + +} \ No newline at end of file diff --git a/scripts/dotnet/OnlineRecognizerResult.cs b/scripts/dotnet/OnlineRecognizerResult.cs index 62f9c047..d13fb0cc 100644 --- a/scripts/dotnet/OnlineRecognizerResult.cs +++ b/scripts/dotnet/OnlineRecognizerResult.cs @@ -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) 2024.5 by 东风破 - -using System.Collections.Generic; -using System.Linq; +using System; using System.Runtime.InteropServices; using System.Text; -using System; namespace SherpaOnnx { + public class OnlineRecognizerResult { public OnlineRecognizerResult(IntPtr handle) diff --git a/scripts/dotnet/OnlineStream.cs b/scripts/dotnet/OnlineStream.cs index fde57401..77a4718a 100644 --- a/scripts/dotnet/OnlineStream.cs +++ b/scripts/dotnet/OnlineStream.cs @@ -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) 2024.5 by 东风破 - -using System.Collections.Generic; -using System.Linq; -using System.Runtime.InteropServices; -using System.Text; using System; +using System.Runtime.InteropServices; namespace SherpaOnnx { + public class OnlineStream : IDisposable { public OnlineStream(IntPtr p) @@ -60,4 +57,5 @@ namespace SherpaOnnx [DllImport(Dll.Filename)] private static extern void InputFinished(IntPtr handle); } + } diff --git a/scripts/dotnet/OnlineTransducerModelConfig.cs b/scripts/dotnet/OnlineTransducerModelConfig.cs index 3c9d73b8..0dc67901 100644 --- a/scripts/dotnet/OnlineTransducerModelConfig.cs +++ b/scripts/dotnet/OnlineTransducerModelConfig.cs @@ -2,14 +2,11 @@ /// Copyright (c) 2023 by manyeyes /// Copyright (c) 2024.5 by 东风破 -using System.Collections.Generic; -using System.Linq; using System.Runtime.InteropServices; -using System.Text; -using System; namespace SherpaOnnx { + [StructLayout(LayoutKind.Sequential)] public struct OnlineTransducerModelConfig { @@ -29,4 +26,5 @@ namespace SherpaOnnx [MarshalAs(UnmanagedType.LPStr)] public string Joiner; } -} + +} \ No newline at end of file diff --git a/scripts/dotnet/OnlineZipformer2CtcModelConfig.cs b/scripts/dotnet/OnlineZipformer2CtcModelConfig.cs index a3dad8cd..987cc5bc 100644 --- a/scripts/dotnet/OnlineZipformer2CtcModelConfig.cs +++ b/scripts/dotnet/OnlineZipformer2CtcModelConfig.cs @@ -2,11 +2,7 @@ /// Copyright (c) 2023 by manyeyes /// Copyright (c) 2024.5 by 东风破 -using System.Collections.Generic; -using System.Linq; using System.Runtime.InteropServices; -using System.Text; -using System; namespace SherpaOnnx { diff --git a/scripts/dotnet/SileroVadModelConfig.cs b/scripts/dotnet/SileroVadModelConfig.cs index 2b02672f..8bf81ea8 100644 --- a/scripts/dotnet/SileroVadModelConfig.cs +++ b/scripts/dotnet/SileroVadModelConfig.cs @@ -1,10 +1,6 @@ /// Copyright (c) 2024 Xiaomi Corporation (authors: Fangjun Kuang) -using System.Linq; -using System.Collections.Generic; using System.Runtime.InteropServices; -using System.Text; -using System; namespace SherpaOnnx { diff --git a/scripts/dotnet/SpeakerEmbeddingExtractor.cs b/scripts/dotnet/SpeakerEmbeddingExtractor.cs index c0b8c72f..4b579935 100644 --- a/scripts/dotnet/SpeakerEmbeddingExtractor.cs +++ b/scripts/dotnet/SpeakerEmbeddingExtractor.cs @@ -1,10 +1,6 @@ -/// Copyright (c) 2024.5 by 东风破 - -using System.Linq; -using System.Collections.Generic; -using System.Runtime.InteropServices; -using System.Text; +/// Copyright (c) 2024.5 by 东风破 using System; +using System.Runtime.InteropServices; namespace SherpaOnnx { @@ -93,4 +89,4 @@ namespace SherpaOnnx private static extern void SherpaOnnxSpeakerEmbeddingExtractorDestroyEmbedding(IntPtr p); } -} \ No newline at end of file +} diff --git a/scripts/dotnet/SpeakerEmbeddingExtractorConfig.cs b/scripts/dotnet/SpeakerEmbeddingExtractorConfig.cs index 6c58a7e6..2d4b31d8 100644 --- a/scripts/dotnet/SpeakerEmbeddingExtractorConfig.cs +++ b/scripts/dotnet/SpeakerEmbeddingExtractorConfig.cs @@ -1,10 +1,6 @@ /// Copyright (c) 2024.5 by 东风破 -using System.Linq; -using System.Collections.Generic; using System.Runtime.InteropServices; -using System.Text; -using System; namespace SherpaOnnx { diff --git a/scripts/dotnet/SpeakerEmbeddingManager.cs b/scripts/dotnet/SpeakerEmbeddingManager.cs index 54814c72..ee3dfa3d 100644 --- a/scripts/dotnet/SpeakerEmbeddingManager.cs +++ b/scripts/dotnet/SpeakerEmbeddingManager.cs @@ -1,10 +1,8 @@ -/// Copyright (c) 2024.5 by 东风破 - -using System.Linq; +/// Copyright (c) 2024.5 by 东风破 +using System; using System.Collections.Generic; using System.Runtime.InteropServices; using System.Text; -using System; namespace SherpaOnnx { @@ -186,4 +184,4 @@ namespace SherpaOnnx [DllImport(Dll.Filename)] private static extern void SherpaOnnxSpeakerEmbeddingManagerFreeAllSpeakers(IntPtr names); } -} \ No newline at end of file +} diff --git a/scripts/dotnet/SpeechSegment.cs b/scripts/dotnet/SpeechSegment.cs index 1128e705..32568ef5 100644 --- a/scripts/dotnet/SpeechSegment.cs +++ b/scripts/dotnet/SpeechSegment.cs @@ -1,17 +1,13 @@ -/// Copyright (c) 2024 Xiaomi Corporation (authors: Fangjun Kuang) - -using System.Linq; -using System.Collections.Generic; -using System.Runtime.InteropServices; -using System.Text; +/// Copyright (c) 2024 Xiaomi Corporation (authors: Fangjun Kuang) using System; +using System.Runtime.InteropServices; namespace SherpaOnnx { public class SpeechSegment { - public SpeechSegment(IntPtr handle) - { + public SpeechSegment(IntPtr handle) + { Impl impl = (Impl)Marshal.PtrToStructure(handle, typeof(Impl)); _start = impl.Start; @@ -28,20 +24,20 @@ namespace SherpaOnnx } } } - } + } - public int _start; - public int Start => _start; + public int _start; + public int Start => _start; - private float[] _samples; - public float[] Samples => _samples; + private float[] _samples; + public float[] Samples => _samples; - [StructLayout(LayoutKind.Sequential)] - struct Impl - { - public int Start; - public IntPtr Samples; - public int Count; - } + [StructLayout(LayoutKind.Sequential)] + struct Impl + { + public int Start; + public IntPtr Samples; + public int Count; + } } } diff --git a/scripts/dotnet/SpokenLanguageIdentification.cs b/scripts/dotnet/SpokenLanguageIdentification.cs index a125d0c5..fe20e58a 100644 --- a/scripts/dotnet/SpokenLanguageIdentification.cs +++ b/scripts/dotnet/SpokenLanguageIdentification.cs @@ -1,10 +1,6 @@ -/// Copyright (c) 2024.5 by 东风破 - -using System.Linq; -using System.Collections.Generic; -using System.Runtime.InteropServices; -using System.Text; +/// Copyright (c) 2024.5 by 东风破 using System; +using System.Runtime.InteropServices; namespace SherpaOnnx { @@ -68,4 +64,4 @@ namespace SherpaOnnx [DllImport(Dll.Filename)] private static extern void SherpaOnnxDestroySpokenLanguageIdentificationResult(IntPtr handle); } -} \ No newline at end of file +} diff --git a/scripts/dotnet/SpokenLanguageIdentificationConfig.cs b/scripts/dotnet/SpokenLanguageIdentificationConfig.cs index 517a7fb2..64a816d4 100644 --- a/scripts/dotnet/SpokenLanguageIdentificationConfig.cs +++ b/scripts/dotnet/SpokenLanguageIdentificationConfig.cs @@ -1,10 +1,6 @@ /// Copyright (c) 2024.5 by 东风破 -using System.Linq; -using System.Collections.Generic; using System.Runtime.InteropServices; -using System.Text; -using System; namespace SherpaOnnx { diff --git a/scripts/dotnet/SpokenLanguageIdentificationResult.cs b/scripts/dotnet/SpokenLanguageIdentificationResult.cs index f62d1735..a60214da 100644 --- a/scripts/dotnet/SpokenLanguageIdentificationResult.cs +++ b/scripts/dotnet/SpokenLanguageIdentificationResult.cs @@ -1,10 +1,7 @@ -/// Copyright (c) 2024.5 by 东风破 - -using System.Linq; -using System.Collections.Generic; +/// Copyright (c) 2024.5 by 东风破 +using System; using System.Runtime.InteropServices; using System.Text; -using System; namespace SherpaOnnx { @@ -43,4 +40,4 @@ namespace SherpaOnnx private String _lang; public String Lang => _lang; } -} \ No newline at end of file +} diff --git a/scripts/dotnet/SpokenLanguageIdentificationWhisperConfig.cs b/scripts/dotnet/SpokenLanguageIdentificationWhisperConfig.cs index 07866d08..eb687d89 100644 --- a/scripts/dotnet/SpokenLanguageIdentificationWhisperConfig.cs +++ b/scripts/dotnet/SpokenLanguageIdentificationWhisperConfig.cs @@ -1,10 +1,6 @@ /// Copyright (c) 2024.5 by 东风破 -using System.Linq; -using System.Collections.Generic; using System.Runtime.InteropServices; -using System.Text; -using System; namespace SherpaOnnx { diff --git a/scripts/dotnet/VadModelConfig.cs b/scripts/dotnet/VadModelConfig.cs index 87fca71d..e999d675 100644 --- a/scripts/dotnet/VadModelConfig.cs +++ b/scripts/dotnet/VadModelConfig.cs @@ -1,10 +1,6 @@ /// Copyright (c) 2024 Xiaomi Corporation (authors: Fangjun Kuang) -using System.Linq; -using System.Collections.Generic; using System.Runtime.InteropServices; -using System.Text; -using System; namespace SherpaOnnx { diff --git a/scripts/dotnet/VoiceActivityDetector.cs b/scripts/dotnet/VoiceActivityDetector.cs index 44ecc2aa..532859f6 100644 --- a/scripts/dotnet/VoiceActivityDetector.cs +++ b/scripts/dotnet/VoiceActivityDetector.cs @@ -1,10 +1,6 @@ -/// Copyright (c) 2024 Xiaomi Corporation (authors: Fangjun Kuang) - -using System.Linq; -using System.Collections.Generic; -using System.Runtime.InteropServices; -using System.Text; +/// Copyright (c) 2024 Xiaomi Corporation (authors: Fangjun Kuang) using System; +using System.Runtime.InteropServices; namespace SherpaOnnx { @@ -112,4 +108,3 @@ namespace SherpaOnnx } } - diff --git a/scripts/dotnet/examples/Common.csproj b/scripts/dotnet/examples/Common.csproj new file mode 100644 index 00000000..5bb58cd8 --- /dev/null +++ b/scripts/dotnet/examples/Common.csproj @@ -0,0 +1,12 @@ + + + + .net6 + + + + + + + + diff --git a/scripts/dotnet/examples/offline-decode-files.csproj b/scripts/dotnet/examples/offline-decode-files.csproj index 6ae4b5a0..ffdfb6ac 100644 --- a/scripts/dotnet/examples/offline-decode-files.csproj +++ b/scripts/dotnet/examples/offline-decode-files.csproj @@ -8,13 +8,8 @@ enable - - /tmp/packages;$(RestoreSources);https://api.nuget.org/v3/index.json - - - - + diff --git a/scripts/dotnet/examples/offline-punctuation.csproj b/scripts/dotnet/examples/offline-punctuation.csproj index 83bd7958..2d94fcb3 100644 --- a/scripts/dotnet/examples/offline-punctuation.csproj +++ b/scripts/dotnet/examples/offline-punctuation.csproj @@ -1,19 +1,15 @@ - - - - Exe - net6.0 - offline_punctuation - enable - enable - - - - /tmp/packages;$(RestoreSources);https://api.nuget.org/v3/index.json - - - - - - - + + + + Exe + net6.0 + offline_punctuation + enable + enable + + + + + + + diff --git a/scripts/dotnet/examples/offline-tts-play.csproj b/scripts/dotnet/examples/offline-tts-play.csproj index f0ced245..d28ae62c 100644 --- a/scripts/dotnet/examples/offline-tts-play.csproj +++ b/scripts/dotnet/examples/offline-tts-play.csproj @@ -8,14 +8,12 @@ enable - - /tmp/packages;$(RestoreSources);https://api.nuget.org/v3/index.json - - - - + + + + diff --git a/scripts/dotnet/examples/offline-tts.csproj b/scripts/dotnet/examples/offline-tts.csproj index 55bbfa06..48548fc4 100644 --- a/scripts/dotnet/examples/offline-tts.csproj +++ b/scripts/dotnet/examples/offline-tts.csproj @@ -8,13 +8,8 @@ enable - - /tmp/packages;$(RestoreSources);https://api.nuget.org/v3/index.json - - - - + diff --git a/scripts/dotnet/examples/online-decode-files.csproj b/scripts/dotnet/examples/online-decode-files.csproj index 740e6dda..0ff58110 100644 --- a/scripts/dotnet/examples/online-decode-files.csproj +++ b/scripts/dotnet/examples/online-decode-files.csproj @@ -8,14 +8,8 @@ enable - - - /tmp/packages;$(RestoreSources);https://api.nuget.org/v3/index.json - - - - + diff --git a/scripts/dotnet/examples/speaker-identification.csproj b/scripts/dotnet/examples/speaker-identification.csproj index 4d43ce0d..7c857fa5 100644 --- a/scripts/dotnet/examples/speaker-identification.csproj +++ b/scripts/dotnet/examples/speaker-identification.csproj @@ -8,12 +8,8 @@ enable - - /tmp/packages;$(RestoreSources);https://api.nuget.org/v3/index.json - - - + diff --git a/scripts/dotnet/examples/speech-recognition-from-microphone.csproj b/scripts/dotnet/examples/speech-recognition-from-microphone.csproj index 12d25a84..901c8a15 100644 --- a/scripts/dotnet/examples/speech-recognition-from-microphone.csproj +++ b/scripts/dotnet/examples/speech-recognition-from-microphone.csproj @@ -8,14 +8,12 @@ enable - - /tmp/packages;$(RestoreSources);https://api.nuget.org/v3/index.json - - - - + + + + diff --git a/scripts/dotnet/examples/spoken-language-identification.csproj b/scripts/dotnet/examples/spoken-language-identification.csproj index ab38ac7e..b8b431a4 100644 --- a/scripts/dotnet/examples/spoken-language-identification.csproj +++ b/scripts/dotnet/examples/spoken-language-identification.csproj @@ -8,12 +8,8 @@ enable - - /tmp/packages;$(RestoreSources);https://api.nuget.org/v3/index.json - - - + diff --git a/scripts/dotnet/examples/streaming-hlg-decoding.csproj b/scripts/dotnet/examples/streaming-hlg-decoding.csproj index 4b982c31..66e0401f 100644 --- a/scripts/dotnet/examples/streaming-hlg-decoding.csproj +++ b/scripts/dotnet/examples/streaming-hlg-decoding.csproj @@ -8,12 +8,8 @@ enable - - /tmp/packages;$(RestoreSources);https://api.nuget.org/v3/index.json - - - + diff --git a/scripts/dotnet/examples/vad-non-streaming-asr-paraformer.csproj b/scripts/dotnet/examples/vad-non-streaming-asr-paraformer.csproj index 4870735f..a5c5f102 100644 --- a/scripts/dotnet/examples/vad-non-streaming-asr-paraformer.csproj +++ b/scripts/dotnet/examples/vad-non-streaming-asr-paraformer.csproj @@ -1,19 +1,15 @@ - - - - Exe - net6.0 - vad_non_streaming_asr_paraformer - enable - enable - - - - /tmp/packages;$(RestoreSources);https://api.nuget.org/v3/index.json - - - - - - - + + + + Exe + net6.0 + vad_non_streaming_asr_paraformer + enable + enable + + + + + + +