Fixed the C api calls and created the TTS project file (#1324)

Co-authored-by: Michael Twohey <mtwohey@americanambulance.com>
This commit is contained in:
Michael Twohey
2024-09-07 08:25:02 -07:00
committed by GitHub
parent 888f74bf3c
commit b409b0a958
6 changed files with 54 additions and 8 deletions

View File

@@ -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,

View File

@@ -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;
}
}

View File

@@ -21,6 +21,9 @@ namespace TTS.Struct
[MarshalAs(UnmanagedType.LPStr)]
public string tokens;
[MarshalAs(UnmanagedType.LPStr)]
public string data_dir;
/// <summary>
/// VITS模型的noise_scale (float默认值= 0.667)
/// </summary>
@@ -34,6 +37,9 @@ namespace TTS.Struct
/// </summary>
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 = "";
}
}
}

View File

@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="NAudio" Version="2.2.1" />
<PackageReference Include="org.k2fsa.sherpa.onnx" Version="1.10.23" />
</ItemGroup>
</Project>

View File

@@ -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;
}
/// <summary>