43 lines
1.5 KiB
C#
43 lines
1.5 KiB
C#
|
|
namespace VoiceCat.App.Notifications;
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// Combines the sound pool and the speech announcer behind the user's <see cref="FeedbackSettings"/>.
|
||
|
|
/// MainForm calls <see cref="PlaySound"/> / <see cref="Speak"/> from inside its existing event
|
||
|
|
/// handlers (which already resolve nicknames and channel membership), so this type only owns the
|
||
|
|
/// "should I, and how" policy — not the event routing.
|
||
|
|
/// </summary>
|
||
|
|
public sealed class EventFeedback : IDisposable
|
||
|
|
{
|
||
|
|
private readonly SoundPlayerPool _sounds = new();
|
||
|
|
private readonly SpeechAnnouncer _speech = new();
|
||
|
|
|
||
|
|
public FeedbackSettings Settings { get; set; }
|
||
|
|
|
||
|
|
public EventFeedback(FeedbackSettings settings) => Settings = settings;
|
||
|
|
|
||
|
|
/// <summary>True when speech is both enabled and actually available on this machine.</summary>
|
||
|
|
public bool SpeechAvailable => _speech.Available;
|
||
|
|
|
||
|
|
public void PlaySound(SoundEvent ev)
|
||
|
|
{
|
||
|
|
if (!Settings.Sounds || Settings.Volume <= 0f) return;
|
||
|
|
// The two opt-in categories are gated by their own flags.
|
||
|
|
if ((ev is SoundEvent.VaStart or SoundEvent.VaStop) && !Settings.SelfTalkSounds) return;
|
||
|
|
if (ev is SoundEvent.Ptt && !Settings.PttSound) return;
|
||
|
|
_sounds.Play(ev);
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>Announce <paramref name="text"/> when spoken feedback is enabled.</summary>
|
||
|
|
public void Speak(string text)
|
||
|
|
{
|
||
|
|
if (!Settings.Speech) return;
|
||
|
|
_speech.Speak(text);
|
||
|
|
}
|
||
|
|
|
||
|
|
public void Dispose()
|
||
|
|
{
|
||
|
|
_sounds.Dispose();
|
||
|
|
_speech.Dispose();
|
||
|
|
}
|
||
|
|
}
|