mirror of
https://github.com/9ParsonsB/Pulsar.git
synced 2025-07-01 16:33:43 -04:00
Notification overhaul and update to avaloniaui 0.10.7
This commit is contained in:
74
ObservatoryCore/NativeNotification/NativeVoice.cs
Normal file
74
ObservatoryCore/NativeNotification/NativeVoice.cs
Normal file
@ -0,0 +1,74 @@
|
||||
using Observatory.Framework;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Speech.Synthesis;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Observatory.NativeNotification
|
||||
{
|
||||
public class NativeVoice
|
||||
{
|
||||
private Queue<NotificationArgs> notificationEvents;
|
||||
private bool processing;
|
||||
|
||||
public NativeVoice()
|
||||
{
|
||||
notificationEvents = new();
|
||||
processing = false;
|
||||
}
|
||||
|
||||
public void EnqueueAndAnnounce(NotificationArgs eventArgs)
|
||||
{
|
||||
notificationEvents.Enqueue(eventArgs);
|
||||
|
||||
if (!processing)
|
||||
{
|
||||
processing = true;
|
||||
ProcessQueueAsync();
|
||||
}
|
||||
}
|
||||
|
||||
private async void ProcessQueueAsync()
|
||||
{
|
||||
await Task.Factory.StartNew(ProcessQueue);
|
||||
}
|
||||
|
||||
private void ProcessQueue()
|
||||
{
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
{
|
||||
var speech = new SpeechSynthesizer()
|
||||
{
|
||||
Volume = Properties.Core.Default.VoiceVolume,
|
||||
Rate = Properties.Core.Default.VoiceRate
|
||||
};
|
||||
speech.SelectVoice(Properties.Core.Default.VoiceSelected);
|
||||
|
||||
while (notificationEvents.Any())
|
||||
{
|
||||
var notification = notificationEvents.Dequeue();
|
||||
|
||||
if (notification.TitleSsml?.Length > 0)
|
||||
{
|
||||
speech.SpeakSsml(notification.TitleSsml);
|
||||
}
|
||||
else
|
||||
{
|
||||
speech.Speak(notification.Title);
|
||||
}
|
||||
|
||||
if (notification.DetailSsml?.Length > 0)
|
||||
{
|
||||
speech.SpeakSsml(notification.DetailSsml);
|
||||
}
|
||||
else
|
||||
{
|
||||
speech.Speak(notification.Detail);
|
||||
}
|
||||
}
|
||||
}
|
||||
processing = false;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user