diff --git a/stardew-access/ScreenReader/ScreenReaderController.cs b/stardew-access/ScreenReader/ScreenReaderController.cs index b515519..f061107 100644 --- a/stardew-access/ScreenReader/ScreenReaderController.cs +++ b/stardew-access/ScreenReader/ScreenReaderController.cs @@ -22,6 +22,12 @@ namespace stardew_access.ScreenReader ScreenReader = screenReaderLinux; } + else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { + var reader = new ScreenReaderMac(); + reader.InitializeScreenReader(); + + ScreenReader = reader; + } else { ScreenReader.InitializeScreenReader(); diff --git a/stardew-access/ScreenReader/ScreenReaderMac.cs b/stardew-access/ScreenReader/ScreenReaderMac.cs new file mode 100644 index 0000000..9fb519e --- /dev/null +++ b/stardew-access/ScreenReader/ScreenReaderMac.cs @@ -0,0 +1,96 @@ +using System; +using System.Diagnostics; +using System.IO; + +namespace stardew_access.ScreenReader +{ + public class ScreenReaderMac : IScreenReader + { + private Process? _speakProcess; + + + public string PrevTextTile + { + get; + set; + } + + public string prevText = "", prevTextTile = " ", prevChatText = "", prevMenuText = ""; + + public void InitializeScreenReader() + { + MainClass.GetMonitor().Log("Screen reader initialized"); + Speak("Mac screen reader ready", true); + } + + public void CloseScreenReader() + { + MainClass.GetMonitor().Log("Screen reader closed"); + } + + public void Say(string text, bool interrupt) + { + if (text == null) return; + MainClass.GetMonitor().Log($"{text}"); + Speak(text, interrupt); + } + + public void SayWithChecker(string text, bool interrupt) + { + if (text == null) return; + MainClass.GetMonitor().Log($"{text}"); + if (text != prevText) { + Speak(text, interrupt); + prevText = text; + } + } + + public void SayWithMenuChecker(string text, bool interrupt) + { + if (text == null) return; + MainClass.GetMonitor().Log($"{text}"); + if (text != prevMenuText) { + Speak(text, interrupt); + prevMenuText = text; + } + } + + public void SayWithChatChecker(string text, bool interrupt) + { + if (text == null) return; + MainClass.GetMonitor().Log($"{text}"); + if (text != prevChatText) { + Speak(text, interrupt); + prevChatText = text; + } + } + + public void SayWithTileQuery(string text, int x, int y, bool interrupt) + { + if (text == null) return; + MainClass.GetMonitor().Log($"{text}"); + if (text != prevTextTile) { + Speak(text, interrupt); + prevTextTile = text; + } + + } + + private void Speak(string text, bool interupt) { + if (interupt) { + if (_speakProcess != null) { + _speakProcess.Kill(); + _speakProcess = null; + } + } + if (_speakProcess == null) { + _speakProcess = new Process(); + _speakProcess.StartInfo.FileName = "say"; + _speakProcess.StartInfo.Verb = "say"; + _speakProcess.StartInfo.RedirectStandardInput = true; + _speakProcess.StartInfo.Arguments = text; + _speakProcess.Start(); + } + } + } +} \ No newline at end of file