mirror of
https://github.com/LorisYounger/VPet.ModMaker.git
synced 2024-08-30 18:22:21 +00:00
支持测试TTS
This commit is contained in:
parent
bee58adeb8
commit
c6a2708e71
Binary file not shown.
@ -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))
|
||||
|
@ -69,6 +69,9 @@
|
||||
</ComboBox>
|
||||
<Button pu:ButtonHelper.CornerRadius="4" Content="保存设置" Background="{DynamicResource SecondaryLight}"
|
||||
BorderBrush="{DynamicResource SecondaryDark}" BorderThickness="2" Grid.Row="5" Margin="5,5,5,5"
|
||||
Grid.ColumnSpan="4" Click="Save_Click" />
|
||||
Grid.ColumnSpan="3" Click="Save_Click" />
|
||||
<Button x:Name="Test" pu:ButtonHelper.CornerRadius="4" Content="测试" Background="{DynamicResource SecondaryLight}"
|
||||
BorderBrush="{DynamicResource SecondaryDark}" BorderThickness="2" Grid.Row="5" Margin="5,5,5,5"
|
||||
Grid.ColumnSpan="1" Click="Test_Click" Grid.Column="3" />
|
||||
</Grid>
|
||||
</Window>
|
||||
|
@ -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);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user