支持语音控件

This commit is contained in:
ZouJin 2023-05-26 03:50:38 +10:00
parent 72d73cff0f
commit 49d1049fc2
8 changed files with 63 additions and 8 deletions

View File

@ -7,7 +7,7 @@
<Grid x:Name="MainGrid" Width="500" Height="500" MouseLeftButtonDown="MainGrid_MouseLeftButtonDown"
x:FieldModifier="public" MouseLeftButtonUp="MainGrid_MouseLeftButtonUp"
MouseRightButtonDown="MainGrid_MouseRightButtonDown" MouseMove="MainGrid_MouseWave">
<MediaElement x:Name="VoicePlayer" LoadedBehavior="Play" UnloadedBehavior="Stop" />
<MediaElement x:Name="VoicePlayer" LoadedBehavior="Manual" UnloadedBehavior="Stop" />
<Grid x:Name="UIGrid_Back" x:FieldModifier="public" />
<Border x:Name="PetGrid" VerticalAlignment="Bottom" />
<Border x:Name="PetGrid2" VerticalAlignment="Bottom" />

View File

@ -107,12 +107,44 @@ namespace VPet_Simulator.Core
Core.TouchEvent.Add(new TouchArea(Core.Graph.GraphConfig.TouchRaisedLocate, Core.Graph.GraphConfig.TouchRaisedSize, DisplayRaised, true));
}
/// <summary>
/// 播放语音
/// 播放语音 语音播放时不会停止播放说话表情
/// </summary>
/// <param name="VoicePath">语音位置</param>
public void PlayVoice(Uri VoicePath)
public void PlayVoice(Uri VoicePath)//, TimeSpan timediff = TimeSpan.Zero) TODO
{
VoicePlayer.Source = VoicePath;
PlayingVoice = true;
Dispatcher.Invoke(() =>
{
VoicePlayer.Clock = new MediaTimeline(VoicePath).CreateClock();
VoicePlayer.Clock.Completed += Clock_Completed;
VoicePlayer.Play();
//Task.Run(() =>
//{
// Thread.Sleep(1000);
// Dispatcher.Invoke(() =>
// {
// if (VoicePlayer?.Clock?.NaturalDuration.HasTimeSpan == true)
// PlayEndTime += VoicePlayer.Clock.NaturalDuration.TimeSpan - TimeSpan.FromSeconds(0.8);
// });
//});
});
}
/// <summary>
/// 声音音量
/// </summary>
public double PlayVoiceVolume
{
get => Dispatcher.Invoke(() => VoicePlayer.Volume);
set => Dispatcher.Invoke(() => VoicePlayer.Volume = value);
}
/// <summary>
/// 当前是否正在播放
/// </summary>
public bool PlayingVoice = false;
private void Clock_Completed(object sender, EventArgs e)
{
PlayingVoice = false;
VoicePlayer.Clock = null;
}
private void SmartMoveTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)

View File

@ -57,6 +57,18 @@ namespace VPet_Simulator.Core
}
else
{
if (m.PlayingVoice)
{
TimeSpan ts = Dispatcher.Invoke(() => m.VoicePlayer?.Clock?.NaturalDuration.HasTimeSpan == true ? (m.VoicePlayer.Clock.NaturalDuration.TimeSpan - m.VoicePlayer.Clock.CurrentTime.Value) : TimeSpan.Zero);
if (ts.TotalSeconds > 2)
{
return;
}
else
{
Console.WriteLine(1);
}
}
Task.Run(() =>
{
Thread.Sleep(timeleft * 50);
@ -78,7 +90,7 @@ namespace VPet_Simulator.Core
}
public Timer EndTimer = new Timer() { Interval = 200 };
public Timer ShowTimer = new Timer() { Interval = 40 };
public Timer ShowTimer = new Timer() { Interval = 50 };
public Timer CloseTimer = new Timer() { Interval = 20 };
int timeleft;
GraphCore.Helper.SayType sayType;
@ -91,7 +103,7 @@ namespace VPet_Simulator.Core
{
if (m.UIGrid.Children.IndexOf(this) != m.UIGrid.Children.Count - 1)
{
Panel.SetZIndex(this, m.UIGrid.Children.Count);
Panel.SetZIndex(this, m.UIGrid.Children.Count);
}
TText.Text = "";
outputtext = text.ToList();

View File

@ -33,7 +33,6 @@ namespace VPet_Simulator.Core
/// </summary>
public int Level => (int)(Math.Sqrt(Exp) / 5) + 1;
/// <summary>
/// 升级所需经验值
/// </summary>
@ -239,6 +238,5 @@ namespace VPet_Simulator.Core
//save.SetFloat("Likability", Likability);
return LPSConvert.SerializeObject(this, "vpet");
}
}
}

View File

@ -72,6 +72,14 @@ namespace VPet_Simulator.Windows.Interface
}
}
/// <summary>
/// 播放声音大小
/// </summary>
public double VoiceVolume
{
get => GetFloat("voicevolume", 0.5);
set => SetFloat("voicevolume", value);
}
/// <summary>
/// 是否为更大的屏幕
/// </summary>
public bool IsBiggerScreen

View File

@ -55,7 +55,10 @@ namespace VPet_Simulator.Windows
mp.Save();
//游戏存档
if (Set != null)
{
Set.VoiceVolume = Main.PlayVoiceVolume;
File.WriteAllText(AppDomain.CurrentDomain.BaseDirectory + @"\Setting.lps", Set.ToString());
}
if (Core != null && Core.Save != null)
File.WriteAllText(AppDomain.CurrentDomain.BaseDirectory + @"\Save.lps", Core.Save.ToLine().ToString());
if (CGPTClient != null)

View File

@ -245,6 +245,7 @@ namespace VPet_Simulator.Windows
Dispatcher.Invoke(() => Main.Say(v.Item1, v.Item2));
}
};
Main.PlayVoiceVolume = Set.VoiceVolume;
DisplayGrid.Child = Main;
Task.Run(() =>
{

View File

@ -0,0 +1 @@
C:/Users/ZouJin/Documents/Visual Studio 2022/Project/VPet.Plugin.DemoClock/VPet.Plugin.EdgeTTS/1101_EdgeTTS