diff --git a/build-wasm-simd-asr.sh b/build-wasm-simd-asr.sh index f5e75504..c1953933 100755 --- a/build-wasm-simd-asr.sh +++ b/build-wasm-simd-asr.sh @@ -20,6 +20,7 @@ if [ x"$EMSCRIPTEN" == x"" ]; then exit 1 else EMSCRIPTEN=$(dirname $(realpath $(which emcc))) + emcc --version fi fi diff --git a/build-wasm-simd-kws.sh b/build-wasm-simd-kws.sh index 301bd871..408fd75a 100755 --- a/build-wasm-simd-kws.sh +++ b/build-wasm-simd-kws.sh @@ -15,6 +15,7 @@ if [ x"$EMSCRIPTEN" == x"" ]; then exit 1 else EMSCRIPTEN=$(dirname $(realpath $(which emcc))) + emcc --version fi fi diff --git a/build-wasm-simd-nodejs.sh b/build-wasm-simd-nodejs.sh index 13bf3c85..43023cbe 100755 --- a/build-wasm-simd-nodejs.sh +++ b/build-wasm-simd-nodejs.sh @@ -22,6 +22,7 @@ if [ x"$EMSCRIPTEN" == x"" ]; then exit 1 else EMSCRIPTEN=$(dirname $(realpath $(which emcc))) + emcc --version fi fi diff --git a/build-wasm-simd-speaker-diarization.sh b/build-wasm-simd-speaker-diarization.sh index da4be038..888abb56 100755 --- a/build-wasm-simd-speaker-diarization.sh +++ b/build-wasm-simd-speaker-diarization.sh @@ -20,6 +20,7 @@ if [ x"$EMSCRIPTEN" == x"" ]; then exit 1 else EMSCRIPTEN=$(dirname $(realpath $(which emcc))) + emcc --version fi fi diff --git a/build-wasm-simd-tts.sh b/build-wasm-simd-tts.sh index 4e37d204..c707bef6 100755 --- a/build-wasm-simd-tts.sh +++ b/build-wasm-simd-tts.sh @@ -20,6 +20,7 @@ if [ x"$EMSCRIPTEN" == x"" ]; then exit 1 else EMSCRIPTEN=$(dirname $(realpath $(which emcc))) + emcc --version fi fi diff --git a/build-wasm-simd-vad-asr.sh b/build-wasm-simd-vad-asr.sh index 4bf899da..62193155 100755 --- a/build-wasm-simd-vad-asr.sh +++ b/build-wasm-simd-vad-asr.sh @@ -21,6 +21,7 @@ if [ x"$EMSCRIPTEN" == x"" ]; then exit 1 else EMSCRIPTEN=$(dirname $(realpath $(which emcc))) + emcc --version fi fi diff --git a/build-wasm-simd-vad.sh b/build-wasm-simd-vad.sh index b73f7f15..2ab11249 100755 --- a/build-wasm-simd-vad.sh +++ b/build-wasm-simd-vad.sh @@ -20,6 +20,7 @@ if [ x"$EMSCRIPTEN" == x"" ]; then exit 1 else EMSCRIPTEN=$(dirname $(realpath $(which emcc))) + emcc --version fi fi diff --git a/dotnet-examples/TTS/PlayAudioPartial/SherpaOnnxGeneratedAudioResultPlayAudio.cs b/dotnet-examples/TTS/PlayAudioPartial/SherpaOnnxGeneratedAudioResultPlayAudio.cs deleted file mode 100644 index 1eb1e356..00000000 --- a/dotnet-examples/TTS/PlayAudioPartial/SherpaOnnxGeneratedAudioResultPlayAudio.cs +++ /dev/null @@ -1,44 +0,0 @@ -using NAudio.Wave; - -namespace TTS.Struct -{ - public sealed partial class SherpaOnnxGeneratedAudioResult - { - private WaveOutEvent waveOut; - private WaveFormat waveFormat; - private BufferedWaveProvider bufferedWaveProvider; - - private int bufferLength = 1; - - public TimeSpan? AudioDuration => bufferedWaveProvider?.BufferedDuration; - - public float PlayProgress => (waveOut?.GetPosition() * 1.0f / bufferLength).Value; - - public void Play() - { - waveOut ??= new WaveOutEvent(); - - waveFormat ??= new WaveFormat(sample_rate, AudioDataBit, Channels); // 32-bit 浮点,单声道 - - if (bufferedWaveProvider == null) - { - bufferedWaveProvider ??= new BufferedWaveProvider(waveFormat); - - var buffer = AudioByteData; - - bufferLength = buffer.Length; - - bufferedWaveProvider.AddSamples(buffer, 0, bufferLength); - bufferedWaveProvider.BufferLength = bufferLength; - waveOut.Init(bufferedWaveProvider); - } - waveOut.Play(); - } - - public void Stop() - { - waveOut?.Stop(); - } - - } -} diff --git a/dotnet-examples/TTS/Program.cs b/dotnet-examples/TTS/Program.cs deleted file mode 100644 index 07bb1325..00000000 --- a/dotnet-examples/TTS/Program.cs +++ /dev/null @@ -1,66 +0,0 @@ -using System.Text; -using TTS; -using TTS.Struct; - -internal class Program -{ - private static void Main(string[] args) - { - SherpaOnnxOfflineTtsConfig sherpaOnnxOfflineTtsConfig = new SherpaOnnxOfflineTtsConfig(); - sherpaOnnxOfflineTtsConfig.model = new SherpaOnnxOfflineTtsModelConfig - { - debug = 0, - num_threads = 4, - provider = "cpu", - vits = new SherpaOnnxOfflineTtsVitsModelConfig - { - //lexicon = "vits-zh-aishell3/lexicon.txt", - //model = "vits-zh-aishell3/vits-aishell3.onnx", - //tokens = "vits-zh-aishell3/tokens.txt", - model = @"C:\Services\Sherpa\model.onnx", - lexicon = "", - tokens = @"C:\Services\Sherpa\tokens.txt", - data_dir = @"C:\Services\Sherpa\espeak-ng-data", - - noise_scale = 0.667f, - noise_scale_w = 0.8f, - length_scale = 1, - }, - - }; - - TTSCore i = new TTSCore(sherpaOnnxOfflineTtsConfig); - - Console.InputEncoding = Encoding.Unicode; - Console.OutputEncoding = Encoding.UTF8; - - while (true) - { - var str = Console.ReadLine(); - var audioResult = i.ToSpeech(str, 40, 1f); - - // audioResult.WriteWAVFile("123.wav");保存本地 - - audioResult.Play(); - - int lastIndex = -1; - while (audioResult.PlayProgress <= 1f) - { - int index = (int)(audioResult.PlayProgress * (str.Length - 1)); - if (lastIndex != index) - { - Console.Write(str[index]); - lastIndex = index; - } - Thread.Sleep(100); - } - - if (++lastIndex < str.Length) - Console.Write(str[lastIndex]); - - Console.WriteLine(); - - } - - } -} diff --git a/dotnet-examples/TTS/Struct/SherpaOnnxGeneratedAudio.cs b/dotnet-examples/TTS/Struct/SherpaOnnxGeneratedAudio.cs deleted file mode 100644 index affc3a03..00000000 --- a/dotnet-examples/TTS/Struct/SherpaOnnxGeneratedAudio.cs +++ /dev/null @@ -1,198 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.InteropServices; -using System.Text; -using System.Threading.Tasks; - -namespace TTS.Struct -{ - /// - /// 生成语音结果 - /// - public sealed partial class SherpaOnnxGeneratedAudioResult : IDisposable - { - public const string Filename = "sherpa-onnx-c-api"; - - /// - /// 销毁非托管内存 - /// - /// - [DllImport(Filename)] - private static extern void SherpaOnnxDestroyOfflineTtsGeneratedAudio(IntPtr ttsGenerateIntptr); - - [DllImport(Filename)] - private static extern int SherpaOnnxWriteWave(IntPtr q, int n, int sample_rate, string filename); - - /// - /// 音频数据比特 - /// - public const int AudioDataBit = 16; - /// - /// 单通道 - /// - public const int Channels = 1; - - /// - /// 原生句柄 - /// - internal IntPtr thisHandle; - - internal readonly IntPtr audioData; - internal readonly int dataSize; - - /// - /// 采样率 - /// - public readonly int sample_rate; - - /// - /// 音频数据指针 - /// - public IntPtr AudioDataIntPtr => audioData; - - /// - /// 数据的大小 - /// - public unsafe int AudioDataLength - { - get - { - return dataSize; - - //float* buffer = (float*)audioData; - //while (*buffer != 0) - // ++buffer; - //return (int)(buffer - (float*)audioData); - } - } - - /// - /// 获得音频数据 float[] - /// 这个内部创建一个数组 - /// - public unsafe float[] AudioFloatData - { - get - { - int length = AudioDataLength; - - float[] floatAudioData = new float[length]; - Marshal.Copy(audioData, floatAudioData, 0, floatAudioData.Length); - return floatAudioData; - } - } - - - /// - /// 获得音频数据 byte[] - /// 这个内部创建一个数组 - /// - public byte[] AudioByteData - { - get - { - byte[] bytes = new byte[AudioDataLength * 2]; - ReadData(bytes, 0); - return bytes; - } - } - - internal SherpaOnnxGeneratedAudioResult(IntPtr intPtr, SherpaOnnxGeneratedAudio sherpaOnnx) - { - this.thisHandle = intPtr; - this.audioData = sherpaOnnx.audioData; - this.dataSize = sherpaOnnx.dataSize; - this.sample_rate = sherpaOnnx.sample_rate; - } - - ~SherpaOnnxGeneratedAudioResult() - { - Dispose(); - } - - /// - /// 读取数据 - /// 没有垃圾产生,自己传递数组进来 - /// - /// 数组 - /// 数组那个位置写入 - /// 写入了多少个 - public int ReadData(float[] audioFloats, int offset) - { - int length = AudioDataLength; - - int c = audioFloats.Length - offset; - length = c >= length ? length : c; - - Marshal.Copy(audioData, audioFloats, offset, length); - return length; - } - - /// - /// 读取数据 - /// 这个内部转换成byte[] 音频数组 - /// 没有垃圾产生,自己传递数组进来 - /// - /// 数组,这个长度需要是AudioDataLength*2大小 - /// 数组那个位置写入 - /// 写入了多少个 - public int ReadData(byte[] audioFloats, int offset) - { - //因为是16bit存储音频数据,所以float会转换成两个字节存储 - var audiodata = AudioFloatData; - - int length = audiodata.Length * 2; - - int c = audioFloats.Length - offset; - c = c % 2 == 0 ? c : c - 1; - - length = c >= length ? length : c; - - int p = length / 2; - - for (int i = 0; i < p; i++) - { - short value = (short)(audiodata[i] * short.MaxValue); - - audioFloats[offset++] = (byte)value; - audioFloats[offset++] = (byte)(value >> 8); - } - - return length; - - } - - /// - /// 写入WAV音频数据 - /// - /// - /// - public bool WriteWAVFile(string filename) - { - return 1 == SherpaOnnxWriteWave(audioData, this.dataSize, this.sample_rate, filename); - } - - public void Dispose() - { - if (this.thisHandle != IntPtr.Zero) - { - SherpaOnnxDestroyOfflineTtsGeneratedAudio(this.thisHandle); - GC.SuppressFinalize(this); - this.thisHandle = IntPtr.Zero; - } - } - } - - [StructLayout(LayoutKind.Sequential)] - internal struct SherpaOnnxGeneratedAudio - { - internal readonly IntPtr audioData; - internal readonly int dataSize; - - /// - /// 采样率 - /// - public readonly int sample_rate; - } -} diff --git a/dotnet-examples/TTS/Struct/SherpaOnnxOfflineTtsConfig.cs b/dotnet-examples/TTS/Struct/SherpaOnnxOfflineTtsConfig.cs deleted file mode 100644 index f33e37dc..00000000 --- a/dotnet-examples/TTS/Struct/SherpaOnnxOfflineTtsConfig.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System.Runtime.InteropServices; - -namespace TTS.Struct -{ - [StructLayout(LayoutKind.Sequential)] - public struct SherpaOnnxOfflineTtsConfig - { - public SherpaOnnxOfflineTtsModelConfig model; - - [MarshalAs(UnmanagedType.LPStr)] - public string rule_fsts; - - public int max_num_sentences; - - [MarshalAs(UnmanagedType.LPStr)] - public string rule_fars; - } -} diff --git a/dotnet-examples/TTS/Struct/SherpaOnnxOfflineTtsModelConfig.cs b/dotnet-examples/TTS/Struct/SherpaOnnxOfflineTtsModelConfig.cs deleted file mode 100644 index 46dd5585..00000000 --- a/dotnet-examples/TTS/Struct/SherpaOnnxOfflineTtsModelConfig.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System.Runtime.InteropServices; - -namespace TTS.Struct -{ - [StructLayout(LayoutKind.Sequential)] - public struct SherpaOnnxOfflineTtsModelConfig - { - /// - /// 模型配置 - /// - public SherpaOnnxOfflineTtsVitsModelConfig vits; - /// - /// 线程数 - /// - public int num_threads; - public int debug; - /// - /// 使用cpu - /// - [MarshalAs(UnmanagedType.LPStr)] - public string provider; - } -} diff --git a/dotnet-examples/TTS/Struct/SherpaOnnxOfflineTtsVitsModelConfig.cs b/dotnet-examples/TTS/Struct/SherpaOnnxOfflineTtsVitsModelConfig.cs deleted file mode 100644 index 266df5ae..00000000 --- a/dotnet-examples/TTS/Struct/SherpaOnnxOfflineTtsVitsModelConfig.cs +++ /dev/null @@ -1,56 +0,0 @@ -using System.Runtime.InteropServices; - -namespace TTS.Struct -{ - [StructLayout(LayoutKind.Sequential)] - public struct SherpaOnnxOfflineTtsVitsModelConfig - { - /// - /// 模型 - /// "vits-zh-aishell3/vits-aishell3.onnx" - /// - [MarshalAs(UnmanagedType.LPStr)] - public string model; - /// - /// 词典文件 - /// "vits-zh-aishell3/lexicon.txt" - /// - [MarshalAs(UnmanagedType.LPStr)] - public string lexicon; - - [MarshalAs(UnmanagedType.LPStr)] - public string tokens; - - [MarshalAs(UnmanagedType.LPStr)] - public string data_dir; - - /// - /// VITS模型的noise_scale (float,默认值= 0.667) - /// - public float noise_scale = 0.667f; - /// - /// VITS模型的noise_scale_w (float,默认值= 0.8) - /// - public float noise_scale_w = 0.8f; - /// - /// 演讲的速度。大→慢;小→更快。(float, default = 1) - /// - public float length_scale = 1f; - - [MarshalAs(UnmanagedType.LPStr)] - public string dict_dir; - - public SherpaOnnxOfflineTtsVitsModelConfig() - { - noise_scale = 0.667f; - noise_scale_w = 0.8f; - length_scale = 1f; - - model = "vits-zh-aishell3/vits-aishell3.onnx"; - lexicon = "vits-zh-aishell3/lexicon.txt"; - tokens = "vits-zh-aishell3/tokens.txt"; - data_dir = ""; - dict_dir = ""; - } - } -} diff --git a/dotnet-examples/TTS/TTS.csproj b/dotnet-examples/TTS/TTS.csproj deleted file mode 100644 index cb1a419e..00000000 --- a/dotnet-examples/TTS/TTS.csproj +++ /dev/null @@ -1,15 +0,0 @@ - - - - Exe - net6.0 - enable - enable - true - - - - - - - diff --git a/dotnet-examples/TTS/TTSCore.cs b/dotnet-examples/TTS/TTSCore.cs deleted file mode 100644 index a15cb19e..00000000 --- a/dotnet-examples/TTS/TTSCore.cs +++ /dev/null @@ -1,75 +0,0 @@ -using System.Runtime.InteropServices; -using TTS.Struct; - -namespace TTS -{ - internal sealed class TTSCore : IDisposable - { - public const string Filename = "sherpa-onnx-c-api"; - - [DllImport(Filename, CallingConvention = CallingConvention.Cdecl)] - private static extern IntPtr SherpaOnnxCreateOfflineTts(SherpaOnnxOfflineTtsConfig handle); - - [DllImport(Filename)] - private static extern IntPtr SherpaOnnxOfflineTtsGenerate(IntPtr createOfflineTtsIntptr, IntPtr text, int sid, float speed); - - [DllImport(Filename)] - private static extern void SherpaOnnxDestroyOfflineTts(IntPtr intPtr); - - /// - /// 原生句柄 - /// - private IntPtr thisHandle; - - public TTSCore(SherpaOnnxOfflineTtsConfig modelConfig) - { - IntPtr ttsHandle = SherpaOnnxCreateOfflineTts(modelConfig); - if (ttsHandle == IntPtr.Zero) - { - throw new InvalidOperationException("Failed to create SherpaOnnx TTS engine."); - } - thisHandle = ttsHandle; - } - - /// - /// 文字转语音 - /// - /// 文字 - /// 音色 - /// 速度 - /// - public SherpaOnnxGeneratedAudioResult ToSpeech(string text, int sid, float speed = 1f) - { - var result = SherpaOnnxOfflineTtsGenerate(thisHandle, Marshal.StringToCoTaskMemUTF8(text), sid, speed); - SherpaOnnxGeneratedAudio impl = (SherpaOnnxGeneratedAudio)Marshal.PtrToStructure(result, typeof(SherpaOnnxGeneratedAudio)); - return new SherpaOnnxGeneratedAudioResult(result, impl); - } - - /// - /// 文字转语音 - /// - /// 文字 - /// 音色 - /// 速度 - /// - public Task ToSpeechAsync(string text, int sid, float speed = 1f) - { - return Task.Run(() => ToSpeech(text, sid, speed)); - } - - ~TTSCore() - { - Dispose(); - } - - public void Dispose() - { - if (this.thisHandle != IntPtr.Zero) - { - SherpaOnnxDestroyOfflineTts(this.thisHandle); - GC.SuppressFinalize(this); - this.thisHandle = IntPtr.Zero; - } - } - } -}