diff --git a/VPet.Plugin.EdgeTTS/1101_EdgeTTS/plugin/VPet.Plugin.VPetTTS.dll b/VPet.Plugin.EdgeTTS/1101_EdgeTTS/plugin/VPet.Plugin.VPetTTS.dll
index 43cad12..bb77bbe 100644
Binary files a/VPet.Plugin.EdgeTTS/1101_EdgeTTS/plugin/VPet.Plugin.VPetTTS.dll and b/VPet.Plugin.EdgeTTS/1101_EdgeTTS/plugin/VPet.Plugin.VPetTTS.dll differ
diff --git a/VPet.Plugin.EdgeTTS/EdgeTTS.cs b/VPet.Plugin.EdgeTTS/EdgeTTS.cs
index aef8e03..03902bf 100644
--- a/VPet.Plugin.EdgeTTS/EdgeTTS.cs
+++ b/VPet.Plugin.EdgeTTS/EdgeTTS.cs
@@ -42,7 +42,7 @@ namespace VPet.Plugin.VPetTTS
{
MW.Main.ToolBar.AddMenuButton(VPet_Simulator.Core.ToolBar.MenuType.DIY, "EdgeTTS", Setting);
}
- private void Main_OnSay(string saythings)
+ public void Main_OnSay(string saythings)
{//说话语音
var path = GraphCore.CachePath + $"\\voice\\{Sub.GetHashCode(saythings):X}.mp3";
if (File.Exists(path))
diff --git a/VPet.Plugin.EdgeTTS/winSetting.xaml b/VPet.Plugin.EdgeTTS/winSetting.xaml
index 196a0a9..dfdcc85 100644
--- a/VPet.Plugin.EdgeTTS/winSetting.xaml
+++ b/VPet.Plugin.EdgeTTS/winSetting.xaml
@@ -69,6 +69,9 @@
+ Grid.ColumnSpan="3" Click="Save_Click" />
+
diff --git a/VPet.Plugin.EdgeTTS/winSetting.xaml.cs b/VPet.Plugin.EdgeTTS/winSetting.xaml.cs
index 0d6644e..1d60aab 100644
--- a/VPet.Plugin.EdgeTTS/winSetting.xaml.cs
+++ b/VPet.Plugin.EdgeTTS/winSetting.xaml.cs
@@ -1,4 +1,7 @@
-using LinePutScript.Converter;
+using EdgeTTS;
+using LinePutScript;
+using LinePutScript.Converter;
+using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.IO;
@@ -37,7 +40,14 @@ namespace VPet.Plugin.VPetTTS
private void Save_Click(object sender, RoutedEventArgs e)
{
- vts.Set.Enable = SwitchOn.IsChecked.Value;
+ if (vts.Set.Enable != SwitchOn.IsChecked.Value)
+ {
+ if (SwitchOn.IsChecked.Value)
+ vts.MW.Main.OnSay += vts.Main_OnSay;
+ else
+ vts.MW.Main.OnSay -= vts.Main_OnSay;
+ vts.Set.Enable = SwitchOn.IsChecked.Value;
+ }
vts.Set.Pitch = PitchSilder.Value;
vts.Set.Rate = RateSilder.Value;
vts.Set.Speaker = CombSpeaker.Text;
@@ -62,5 +72,38 @@ namespace VPet.Plugin.VPetTTS
{
vts.winSetting = null;
}
+
+ private void Test_Click(object sender, RoutedEventArgs e)
+ {
+ Test.IsEnabled = false;
+ var cbt = CombSpeaker.Text;
+ var pit = $"{(PitchSilder.Value >= 0 ? "+" : "")}{PitchSilder.Value:f2}Hz";
+ var rat = $"{(RateSilder.Value >= 0 ? "+" : "")}{RateSilder.Value:f2}%";
+ Task.Run(() =>
+ {
+ var path = GraphCore.CachePath + $"\\voice\\{DateTime.Now.Ticks:X}.mp3";
+ if (File.Exists(path))
+ {
+ File.Delete(path);
+ }
+
+ var res = vts.etts.SynthesisAsync($"你好,主人\n现在是 {DateTime.Now}", cbt, pit, rat).Result;
+ if (res.Code == ResultCode.Success)
+ {
+ FileStream fs = new FileStream(path, FileMode.OpenOrCreate);
+ BinaryWriter w = new BinaryWriter(fs);
+ w.Write(res.Data.ToArray());
+ fs.Close();
+ fs.Dispose();
+ w.Dispose();
+ vts.MW.Main.PlayVoice(new Uri(path));
+ }
+ else
+ {
+ MessageBox.Show($"错误代码: {res.Code}\n消息: {res.Message}", "生成失败");
+ }
+ Dispatcher.Invoke(() => Test.IsEnabled = true);
+ });
+ }
}
}