using Prismatoid; namespace VoiceCat.App.Notifications; /// /// Spoken event announcements via Prismatoid (bindings for the Prism speech library — /// integrates with the active screen reader / system speech, no extra runtime deps). /// /// All construction and calls are wrapped so a machine with no available speech backend simply /// degrades to silence rather than crashing the app. /// public sealed class SpeechAnnouncer : IDisposable { private readonly PrismContext? _context; private readonly object? _backend; // SpeechBackend; held as object to keep this resilient public SpeechAnnouncer() { try { _context = new PrismContext(); _backend = _context.AcquireBestBackend(); } catch { _context?.Dispose(); _context = null; _backend = null; } } /// True when a speech backend is available on this machine. public bool Available => _backend is not null; /// Speak . Queued (does not interrupt prior speech) so a /// burst of events is read in order. public void Speak(string text) { if (string.IsNullOrWhiteSpace(text)) return; try { if (_backend is { } b) ((dynamic)b).Speak(text, interrupt: false); } catch { /* never surface a speech failure */ } } public void Dispose() { try { (_backend as IDisposable)?.Dispose(); } catch { /* ignore */ } _context?.Dispose(); } }