diff --git a/Knossos.NET.Desktop/Assets/utils/win/KSapi.exe b/Knossos.NET.Desktop/Assets/utils/win/KSapi.exe
deleted file mode 100644
index 59e78b1a..00000000
Binary files a/Knossos.NET.Desktop/Assets/utils/win/KSapi.exe and /dev/null differ
diff --git a/Knossos.NET.Desktop/Assets/utils/win/KSapi_x86.exe b/Knossos.NET.Desktop/Assets/utils/win/KSapi_x86.exe
deleted file mode 100644
index eff7fe86..00000000
Binary files a/Knossos.NET.Desktop/Assets/utils/win/KSapi_x86.exe and /dev/null differ
diff --git a/Knossos.NET.Desktop/Knossos.NET.Desktop.csproj b/Knossos.NET.Desktop/Knossos.NET.Desktop.csproj
index f5f5578f..2edb769e 100644
--- a/Knossos.NET.Desktop/Knossos.NET.Desktop.csproj
+++ b/Knossos.NET.Desktop/Knossos.NET.Desktop.csproj
@@ -11,6 +11,7 @@
copyused
true
true
+ AnyCPU;x64
@@ -27,27 +28,76 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ <_IsWin Condition="$(RuntimeIdentifier.StartsWith('win')) Or
+ ($(RuntimeIdentifier) == '' And $([MSBuild]::IsOSPlatform('Windows')))">true
+ <_IsLinux Condition="$(RuntimeIdentifier.StartsWith('linux')) Or
+ ($(RuntimeIdentifier) == '' And $([MSBuild]::IsOSPlatform('Linux')))">true
+ <_IsOsx Condition="$(RuntimeIdentifier.StartsWith('osx')) Or
+ ($(RuntimeIdentifier) == '' And $([MSBuild]::IsOSPlatform('OSX')))">true
+
+
+ <_IsX64 Condition="$(RuntimeIdentifier.Contains('x64')) Or
+ ('$(RuntimeIdentifier)' == '' And '$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)' == 'X64')">true
+ <_IsX86 Condition="$(RuntimeIdentifier.Contains('x86')) Or
+ ('$(RuntimeIdentifier)' == '' And '$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)' == 'X86')">true
+ <_IsArm64 Condition="$(RuntimeIdentifier.Contains('arm64')) Or
+ ('$(RuntimeIdentifier)' == '' And '$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)' == 'Arm64')">true
+ <_IsRiscV64 Condition="$(RuntimeIdentifier.Contains('riscv64'))">true
+
+
+
+
+
+ PreserveNewest
+ KSapi.dll
+
+
+
+
+ PreserveNewest
+ KSapi.dll
+
+
+
+
+ PreserveNewest
+ KSapi.dll
+
+
-
+
+
\ No newline at end of file
diff --git a/Knossos.NET.Desktop/precompiled/windows/arm64/KSapi.dll b/Knossos.NET.Desktop/precompiled/windows/arm64/KSapi.dll
new file mode 100644
index 00000000..870b2420
Binary files /dev/null and b/Knossos.NET.Desktop/precompiled/windows/arm64/KSapi.dll differ
diff --git a/Knossos.NET.Desktop/precompiled/windows/x64/KSapi.dll b/Knossos.NET.Desktop/precompiled/windows/x64/KSapi.dll
new file mode 100644
index 00000000..fa4669cf
Binary files /dev/null and b/Knossos.NET.Desktop/precompiled/windows/x64/KSapi.dll differ
diff --git a/Knossos.NET.Desktop/precompiled/windows/x86/KSapi.dll b/Knossos.NET.Desktop/precompiled/windows/x86/KSapi.dll
new file mode 100644
index 00000000..4d309b25
Binary files /dev/null and b/Knossos.NET.Desktop/precompiled/windows/x86/KSapi.dll differ
diff --git a/Knossos.NET/Classes/KSapi.cs b/Knossos.NET/Classes/KSapi.cs
new file mode 100644
index 00000000..6fcbaf33
--- /dev/null
+++ b/Knossos.NET/Classes/KSapi.cs
@@ -0,0 +1,41 @@
+using System.Runtime.InteropServices;
+
+namespace Knossos.NET.Classes
+{
+ public static class KSapi
+ {
+ private const string Dll = "KSapi";
+ private static bool inited;
+ private static readonly object gate = new();
+
+ [DllImport(Dll, CallingConvention = CallingConvention.Cdecl)]
+ private static extern int KSapi_Init();
+ [DllImport(Dll, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
+ private static extern int KSapi_Speak(string text, int voiceIndex, int volume);
+ [DllImport(Dll, CallingConvention = CallingConvention.Cdecl)]
+ private static extern void KSapi_Stop();
+ [DllImport(Dll, CallingConvention = CallingConvention.Cdecl)]
+ private static extern void KSapi_Shutdown();
+
+ public static void Stop()
+ {
+ try
+ {
+ if (inited) KSapi_Stop();
+ }
+ catch { }
+ }
+
+ public static void Speak(string text, int voice, int vol)
+ {
+ try
+ {
+ lock (gate)
+ {
+ if (!inited) { KSapi_Init(); inited = true; }
+ }
+ KSapi_Speak(text, voice, vol);
+ }catch { }
+ }
+ }
+}
diff --git a/Knossos.NET/Classes/Knossos.cs b/Knossos.NET/Classes/Knossos.cs
index c18bc571..b94219c4 100644
--- a/Knossos.NET/Classes/Knossos.cs
+++ b/Knossos.NET/Classes/Knossos.cs
@@ -1743,58 +1743,19 @@ public async static void Tts(string text, int? voice_index = null, string? voice
{
if (KnUtils.IsWindows)
{
- if (ttsObject != null)
- {
- var sp = (Process)ttsObject;
- sp.Kill();
- ttsObject = null;
- }
- if (text != string.Empty)
+ KSapi.Stop();
+
+ if (!string.IsNullOrEmpty(text))
{
- if (!File.Exists(KnUtils.GetKnossosDataFolderPath() + Path.DirectorySeparatorChar + "KSapi.exe"))
- {
- if (KnUtils.CpuArch == "X86")
- {
- using (var fileStream = File.Create(KnUtils.GetKnossosDataFolderPath() + Path.DirectorySeparatorChar + "KSapi.exe"))
- {
- AssetLoader.Open(new Uri("avares://Knossos.NET.Desktop/Assets/utils/win/KSapi_x86.exe")).CopyTo(fileStream);
- fileStream.Close();
- }
- }
- else
- {
- using (var fileStream = File.Create(KnUtils.GetKnossosDataFolderPath() + Path.DirectorySeparatorChar + "KSapi.exe"))
- {
- AssetLoader.Open(new Uri("avares://Knossos.NET.Desktop/Assets/utils/win/KSapi.exe")).CopyTo(fileStream);
- fileStream.Close();
- }
- }
- }
- await Task.Run(async () =>
+ var voice = voice_index ?? globalSettings.ttsVoice;
+ var vol = volume ?? globalSettings.ttsVolume;
+
+ await Task.Run(() =>
{
- //Max cmdline lenght is 8192, lets limit the text to 7500
- if(text.Length > 7500)
- {
- text = text.Substring(0, 7500);
- }
- await Task.Delay(300);
- var voice = globalSettings.ttsVoice;
- var vol = globalSettings.ttsVolume;
- if (voice_index.HasValue)
- voice = voice_index.Value;
- if (volume.HasValue)
- vol = volume.Value;
- using var ttsProcess = new Process();
- ttsProcess.StartInfo.FileName = KnUtils.GetKnossosDataFolderPath() + Path.DirectorySeparatorChar + "KSapi.exe";
- ttsProcess.StartInfo.Arguments = "-text \"" + text + "\" -voice " + voice + " -vol " + vol;
- ttsProcess.StartInfo.UseShellExecute = false;
- ttsProcess.StartInfo.CreateNoWindow = true;
- ttsObject = ttsProcess;
- ttsProcess.Start();
- ttsProcess.WaitForExit();
- ttsObject = null;
+ KSapi.Speak(text, voice!.Value, Math.Clamp(vol, 0, 100));
+
if (callBack != null)
- await Dispatcher.UIThread.InvokeAsync(() => callBack(), DispatcherPriority.Background);
+ Dispatcher.UIThread.InvokeAsync(() => callBack(), DispatcherPriority.Background);
});
}
}