EdgeTTS 支持自定义设置

This commit is contained in:
ZouJin 2023-05-26 03:50:18 +10:00
parent c9ccde31fd
commit 370a62ce27
11 changed files with 206 additions and 29 deletions

View File

@ -1,2 +1,4 @@
vupmod#DemoClock:|author#lorisyounger:|gamever#100:|ver#100:|
intro#给桌宠添加一个时钟显示的功能,这算是代码嵌入类型MOD的DEMO:|
intro#给桌宠添加一个时钟显示的功能/com这算是代码嵌入类型MOD的DEMO:|
authorid#253101309:|
itemid#2980456794:|

View File

@ -62,6 +62,7 @@ namespace VPet.Plugin.DemoClock
public MenuItem mTiming;
public long CountDownLength;
public winSetting winSetting;
public DemoClock(IMainWindow mainwin) : base(mainwin)
{
}
@ -140,7 +141,15 @@ namespace VPet.Plugin.DemoClock
public override void Setting()
{
new winSetting(this).Show();
if (winSetting == null)
{
winSetting = new winSetting(this);
winSetting.Show();
}
else
{
winSetting.Topmost = true;
}
}
}
}

View File

@ -5,7 +5,7 @@
xmlns:local="clr-namespace:VPet.Plugin.DemoClock" mc:Ignorable="d"
xmlns:pu="clr-namespace:Panuon.WPF.UI;assembly=Panuon.WPF.UI" Title="Demo Clock 设置" Width="450" FontSize="16"
Height="Auto" ResizeMode="NoResize" WindowState="Normal" SizeToContent="Height"
Background="{DynamicResource PrimaryLighter}">
Background="{DynamicResource PrimaryLighter}" Closed="Window_Closed">
<Window.Resources>
<ResourceDictionary Source="/VPet-Simulator.Windows.Interface;component/ResourceStyle.xaml" />
</Window.Resources>

View File

@ -169,5 +169,10 @@ namespace VPet.Plugin.DemoClock
break;
}
}
private void Window_Closed(object sender, EventArgs e)
{
Master.winSetting = null;
}
}
}

View File

@ -9,22 +9,22 @@ using LinePutScript.Converter;
using LinePutScript;
using System.IO;
using VPet_Simulator.Core;
using System.Windows.Controls;
using System.Windows;
namespace VPet.Plugin.VPetTTS
{
public class VPETTTS : MainPlugin
public class EdgeTTS : MainPlugin
{
IMainWindow mw;
EdgeTTSClient etts;
Setting Set;
public VPETTTS(IMainWindow mainwin) : base(mainwin)
public EdgeTTSClient etts;
public Setting Set;
public EdgeTTS(IMainWindow mainwin) : base(mainwin)
{
mw = mainwin;
etts = new EdgeTTSClient();
}
public override void LoadPlugin()
{
etts = new EdgeTTSClient();
var line = MW.Set.FindLine("DemoClock");
var line = MW.Set.FindLine("EdgeTTS");
if (line == null)
{
Set = new Setting();
@ -35,16 +35,21 @@ namespace VPet.Plugin.VPetTTS
}
if (!Directory.Exists(GraphCore.CachePath + @"\voice"))
Directory.CreateDirectory(GraphCore.CachePath + @"\voice");
mw.Main.OnSay += Main_OnSay;
if (Set.Enable)
MW.Main.OnSay += Main_OnSay;
}
public override void LoadDIY()
{
MW.Main.ToolBar.AddMenuButton(VPet_Simulator.Core.ToolBar.MenuType.Setting, "EdgeTTS", Setting);
}
private void Main_OnSay(string saythings)
{//说话语音
var path = GraphCore.CachePath + $"\\voice\\{Sub.GetHashCode(saythings):X}.mp3";
if (File.Exists(path))
{
mw.Main.PlayVoice(new Uri(path));
}else
MW.Main.PlayVoice(new Uri(path));
}
else
{
var res = etts.SynthesisAsync(saythings, Set.Speaker, Set.PitchStr, Set.RateStr).Result;
if (res.Code == ResultCode.Success)
@ -55,16 +60,24 @@ namespace VPet.Plugin.VPetTTS
fs.Close();
fs.Dispose();
w.Dispose();
mw.Main.PlayVoice(new Uri(path));
MW.Main.PlayVoice(new Uri(path));
}
}
}
}
//public override void Save()
//{
// MW.Set.Remove("DemoClock");
// MW.Set.Add(LPSConvert.SerializeObject(Set, "DemoClock"));
//}
public winSetting winSetting;
public override void Setting()
{
if (winSetting == null)
{
winSetting = new winSetting(this);
winSetting.Show();
}
else
{
winSetting.Topmost = true;
}
}
public override string PluginName => "EdgeTTS";
}
}

View File

@ -9,12 +9,6 @@ namespace VPet.Plugin.VPetTTS
{
public class Setting
{
/// <summary>
/// 音量大小
/// </summary>
[Line]
public int Volume { get; set; } = 100;
/// <summary>
/// 语速
/// </summary>
@ -54,5 +48,10 @@ namespace VPet.Plugin.VPetTTS
/// </summary>
[Line]
public string Speaker { get; set; } = "zh-CN-XiaoyiNeural";
/// <summary>
/// 启用EdgeTTS
/// </summary>
[Line]
public bool Enable { get; set; } = true;
}
}

View File

@ -53,6 +53,7 @@
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xaml" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
@ -68,12 +69,21 @@
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<Compile Include="VPETTTS.cs" />
<Compile Include="EdgeTTS.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Setting.cs" />
<Compile Include="winSetting.xaml.cs">
<DependentUpon>winSetting.xaml</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Page Include="winSetting.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View File

@ -0,0 +1,74 @@
<Window x:Class="VPet.Plugin.VPetTTS.winSetting" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:System="clr-namespace:System;assembly=mscorlib"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:VPet.Plugin.VPetTTS"
mc:Ignorable="d" xmlns:pu="clr-namespace:Panuon.WPF.UI;assembly=Panuon.WPF.UI" Title="EdgeTTS 设置" Width="450"
FontSize="16" Height="Auto" ResizeMode="NoResize" WindowState="Normal" SizeToContent="Height"
Background="{DynamicResource PrimaryLighter}" Closed="Window_Closed">
<Window.Resources>
<ResourceDictionary Source="/VPet-Simulator.Windows.Interface;component/ResourceStyle.xaml" />
</Window.Resources>
<Grid Margin="8" Background="{DynamicResource PrimaryLighter}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="15" />
<ColumnDefinition Width="3*" />
<ColumnDefinition Width="1*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="40" />
<RowDefinition Height="40" />
<RowDefinition Height="40" />
<RowDefinition Height="40" />
<RowDefinition Height="40" />
<RowDefinition Height="40" />
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Text="启用" VerticalAlignment="Center" />
<TextBlock Grid.Row="1" Text="音量" VerticalAlignment="Center" />
<TextBlock Grid.Row="2" Text="音调" VerticalAlignment="Center" />
<TextBlock Grid.Row="3" Text="语速" VerticalAlignment="Center" />
<TextBlock Grid.Row="4" Text="讲述人" VerticalAlignment="Center" />
<pu:Switch x:Name="SwitchOn" BorderBrush="{DynamicResource DARKPrimaryDark}"
CheckedBackground="{DynamicResource DARKPrimary}" CheckedBorderBrush="{DynamicResource DARKPrimary}"
Background="Transparent" BoxWidth="35" BoxHeight="18" ToggleSize="14" ToggleShadowColor="{x:Null}"
ToggleBrush="{DynamicResource DARKPrimaryDark}" Content="启用 EdgeTTS"
CheckedToggleBrush="{DynamicResource DARKPrimaryText}" Grid.Column="2" />
<pu:NumberInput Grid.Row="1" Grid.Column="3" Minimum="0" MaxHeight="350" Margin="5"
Value="{Binding Value, ElementName=VolumeSilder}" CornerRadius="3" Maximum="100" />
<Slider Grid.Row="1" Grid.Column="2" x:Name="VolumeSilder" Maximum="100" Value="100" VerticalAlignment="Center"
Background="{DynamicResource DARKPrimaryLighter}" LargeChange="10" SmallChange="2"
pu:SliderHelper.CoveredBackground="{DynamicResource DARKPrimaryDarker}" />
<pu:NumberInput Grid.Row="2" Grid.Column="3" Margin="5" Minimum="-50" Maximum="50"
Value="{Binding Value, ElementName=PitchSilder}" CornerRadius="3" />
<Slider Grid.Row="2" Grid.Column="2" x:Name="PitchSilder" Minimum="-50" Maximum="50" VerticalAlignment="Center"
Background="{DynamicResource DARKPrimaryLighter}" LargeChange="2" SmallChange=".5"
pu:SliderHelper.CoveredBackground="{DynamicResource DARKPrimaryDarker}" />
<pu:NumberInput Grid.Row="3" Grid.Column="3" Margin="5" Minimum="-200" Maximum="200"
Value="{Binding Value, ElementName=RateSilder}" CornerRadius="3" />
<Slider x:Name="RateSilder" Grid.Row="3" Grid.Column="2" Minimum="-200" Maximum="200" VerticalAlignment="Center"
Background="{DynamicResource DARKPrimaryLighter}" LargeChange="5" SmallChange="1"
pu:SliderHelper.CoveredBackground="{DynamicResource DARKPrimaryDarker}" />
<ComboBox x:Name="CombSpeaker" Grid.Row="4" Grid.Column="2" Style="{DynamicResource StandardComboBoxStyle}"
FontSize="16" Margin="5" SelectedIndex="1">
<System:String>zh-CN-XiaoxiaoNeural</System:String>
<System:String>zh-CN-XiaoyiNeural</System:String>
<System:String>zh-CN-YunjianNeural</System:String>
<System:String>zh-CN-YunxiNeural</System:String>
<System:String>zh-CN-YunxiaNeural</System:String>
<System:String>zh-CN-YunyangNeural</System:String>
<System:String>zh-CN-liaoning-XiaobeiNeural</System:String>
<System:String>zh-CN-shaanxi-XiaoniNeural</System:String>
<System:String>zh-HK-HiuGaaiNeural</System:String>
<System:String>zh-HK-HiuMaanNeural</System:String>
<System:String>zh-HK-WanLungNeural</System:String>
<System:String>zh-TW-HsiaoChenNeural</System:String>
<System:String>zh-TW-HsiaoYuNeural</System:String>
<System:String>zh-TW-YunJheNeural</System:String>
</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>
</Window>

View File

@ -0,0 +1,65 @@
using LinePutScript.Converter;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using VPet_Simulator.Core;
namespace VPet.Plugin.VPetTTS
{
/// <summary>
/// winSetting.xaml 的交互逻辑
/// </summary>
public partial class winSetting : Window
{
EdgeTTS vts;
public winSetting(EdgeTTS vts)
{
InitializeComponent();
this.vts = vts;
SwitchOn.IsChecked = vts.Set.Enable;
//TODO VolumeSilder
PitchSilder.Value = vts.Set.Pitch;
RateSilder.Value = vts.Set.Rate;
CombSpeaker.Text = vts.Set.Speaker;
}
private void Save_Click(object sender, RoutedEventArgs e)
{
vts.Set.Enable = SwitchOn.IsChecked.Value;
vts.Set.Pitch = PitchSilder.Value;
vts.Set.Rate = RateSilder.Value;
vts.Set.Speaker = CombSpeaker.Text;
vts.MW.Set.Remove("DemoClock");
vts.MW.Set.Add(LPSConvert.SerializeObject(vts.Set, "DemoClock"));
foreach (var tmpfile in Directory.GetFiles(GraphCore.CachePath + @"\voice"))
{
try
{
File.Delete(tmpfile);
}
finally
{
}
}
Close();
}
private void Window_Closed(object sender, EventArgs e)
{
vts.winSetting = null;
}
}
}