diff --git a/dotnet-examples/TTS/Program.cs b/dotnet-examples/TTS/Program.cs index 7081040d..07bb1325 100644 --- a/dotnet-examples/TTS/Program.cs +++ b/dotnet-examples/TTS/Program.cs @@ -14,9 +14,13 @@ internal class Program provider = "cpu", vits = new SherpaOnnxOfflineTtsVitsModelConfig { - lexicon = "vits-zh-aishell3/lexicon.txt", - model = "vits-zh-aishell3/vits-aishell3.onnx", - tokens = "vits-zh-aishell3/tokens.txt", + //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, diff --git a/dotnet-examples/TTS/Struct/SherpaOnnxOfflineTtsConfig.cs b/dotnet-examples/TTS/Struct/SherpaOnnxOfflineTtsConfig.cs index 1d20264e..f33e37dc 100644 --- a/dotnet-examples/TTS/Struct/SherpaOnnxOfflineTtsConfig.cs +++ b/dotnet-examples/TTS/Struct/SherpaOnnxOfflineTtsConfig.cs @@ -6,5 +6,13 @@ namespace TTS.Struct 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/SherpaOnnxOfflineTtsVitsModelConfig.cs b/dotnet-examples/TTS/Struct/SherpaOnnxOfflineTtsVitsModelConfig.cs index 4b37d81b..266df5ae 100644 --- a/dotnet-examples/TTS/Struct/SherpaOnnxOfflineTtsVitsModelConfig.cs +++ b/dotnet-examples/TTS/Struct/SherpaOnnxOfflineTtsVitsModelConfig.cs @@ -21,6 +21,9 @@ namespace TTS.Struct [MarshalAs(UnmanagedType.LPStr)] public string tokens; + [MarshalAs(UnmanagedType.LPStr)] + public string data_dir; + /// /// VITS模型的noise_scale (float,默认值= 0.667) /// @@ -34,6 +37,9 @@ namespace TTS.Struct /// public float length_scale = 1f; + [MarshalAs(UnmanagedType.LPStr)] + public string dict_dir; + public SherpaOnnxOfflineTtsVitsModelConfig() { noise_scale = 0.667f; @@ -43,6 +49,8 @@ namespace TTS.Struct 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 new file mode 100644 index 00000000..cb1a419e --- /dev/null +++ b/dotnet-examples/TTS/TTS.csproj @@ -0,0 +1,15 @@ + + + + Exe + net6.0 + enable + enable + true + + + + + + + diff --git a/dotnet-examples/TTS/TTSCore.cs b/dotnet-examples/TTS/TTSCore.cs index 63735a8c..a15cb19e 100644 --- a/dotnet-examples/TTS/TTSCore.cs +++ b/dotnet-examples/TTS/TTSCore.cs @@ -7,7 +7,7 @@ namespace TTS { public const string Filename = "sherpa-onnx-c-api"; - [DllImport(Filename)] + [DllImport(Filename, CallingConvention = CallingConvention.Cdecl)] private static extern IntPtr SherpaOnnxCreateOfflineTts(SherpaOnnxOfflineTtsConfig handle); [DllImport(Filename)] @@ -23,7 +23,12 @@ namespace TTS public TTSCore(SherpaOnnxOfflineTtsConfig modelConfig) { - thisHandle = SherpaOnnxCreateOfflineTts(modelConfig); + IntPtr ttsHandle = SherpaOnnxCreateOfflineTts(modelConfig); + if (ttsHandle == IntPtr.Zero) + { + throw new InvalidOperationException("Failed to create SherpaOnnx TTS engine."); + } + thisHandle = ttsHandle; } /// diff --git a/dotnet-examples/sherpa-onnx.sln b/dotnet-examples/sherpa-onnx.sln index fa754d8c..397fe99e 100644 --- a/dotnet-examples/sherpa-onnx.sln +++ b/dotnet-examples/sherpa-onnx.sln @@ -23,11 +23,13 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "offline-punctuation", "offl EndProject 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}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Common", "Common\Common.csproj", "{401E963F-E25A-43CE-987D-8DB2D4715756}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "keyword-spotting-from-files", "keyword-spotting-from-files\keyword-spotting-from-files.csproj", "{A87EDD31-D654-4C9F-AED7-F6F2825659BD}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "keyword-spotting-from-files", "keyword-spotting-from-files\keyword-spotting-from-files.csproj", "{A87EDD31-D654-4C9F-AED7-F6F2825659BD}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "keyword-spotting-from-microphone", "keyword-spotting-from-microphone\keyword-spotting-from-microphone.csproj", "{AEE0ED2B-C86F-4952-863C-EAD3219CB4EC}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "keyword-spotting-from-microphone", "keyword-spotting-from-microphone\keyword-spotting-from-microphone.csproj", "{AEE0ED2B-C86F-4952-863C-EAD3219CB4EC}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TTS", "TTS\TTS.csproj", "{DACE4A18-4FC8-4437-92BF-5A90BA81286C}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -87,6 +89,10 @@ Global {AEE0ED2B-C86F-4952-863C-EAD3219CB4EC}.Debug|Any CPU.Build.0 = Debug|Any CPU {AEE0ED2B-C86F-4952-863C-EAD3219CB4EC}.Release|Any CPU.ActiveCfg = Release|Any CPU {AEE0ED2B-C86F-4952-863C-EAD3219CB4EC}.Release|Any CPU.Build.0 = Release|Any CPU + {DACE4A18-4FC8-4437-92BF-5A90BA81286C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DACE4A18-4FC8-4437-92BF-5A90BA81286C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DACE4A18-4FC8-4437-92BF-5A90BA81286C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DACE4A18-4FC8-4437-92BF-5A90BA81286C}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE