diff --git a/stardew-access/ScreenReader/ScreenReaderController.cs b/stardew-access/ScreenReader/ScreenReaderController.cs index f061107..53d1905 100644 --- a/stardew-access/ScreenReader/ScreenReaderController.cs +++ b/stardew-access/ScreenReader/ScreenReaderController.cs @@ -6,16 +6,9 @@ namespace stardew_access.ScreenReader { public IScreenReader Initialize() { - IScreenReader ScreenReader = new ScreenReaderWindows(); // Default is windows + IScreenReader ScreenReader = new ScreenReaderMac(); // Mac by default - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - ScreenReaderWindows screenReaderWindows = new ScreenReaderWindows(); - screenReaderWindows.InitializeScreenReader(); - - ScreenReader = screenReaderWindows; - } - else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) +if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { ScreenReaderLinux screenReaderLinux = new ScreenReaderLinux(); screenReaderLinux.InitializeScreenReader(); diff --git a/stardew-access/ScreenReader/ScreenReaderMac.cs b/stardew-access/ScreenReader/ScreenReaderMac.cs index 22d5ae6..5b20745 100644 --- a/stardew-access/ScreenReader/ScreenReaderMac.cs +++ b/stardew-access/ScreenReader/ScreenReaderMac.cs @@ -11,40 +11,42 @@ namespace stardew_access.ScreenReader public string PrevTextTile { - get; - set; + get { return prevTextTile; } + set { prevTextTile = value; } } public string prevText = "", prevTextTile = " ", prevChatText = "", prevMenuText = ""; public void InitializeScreenReader() { - MainClass.GetMonitor().Log("Screen reader initialized"); + MainClass.InfoLog("Screen reader initialized"); _speakProcess = new Process(); _speakProcess.StartInfo.FileName = "mac"; _speakProcess.StartInfo.Verb = "mac"; _speakProcess.StartInfo.RedirectStandardInput = true; _speakProcess.Start(); + // set rate (probably should be done through a config parameter) +_speakProcess.StandardInput.WriteLine("r600"); Speak("Mac screen reader ready", true); } public void CloseScreenReader() { - MainClass.GetMonitor().Log("Screen reader closed"); + MainClass.InfoLog("Screen reader closed"); _speakProcess.Kill(); } public void Say(string text, bool interrupt) { if (text == null) return; - MainClass.GetMonitor().Log($"{text}"); + MainClass.InfoLog($"{text}"); Speak(text, interrupt); } public void SayWithChecker(string text, bool interrupt) { if (text == null) return; - MainClass.GetMonitor().Log($"{text}"); + MainClass.InfoLog($"{text}"); if (text != prevText) { Speak(text, interrupt); @@ -55,7 +57,7 @@ namespace stardew_access.ScreenReader public void SayWithMenuChecker(string text, bool interrupt) { if (text == null) return; - MainClass.GetMonitor().Log($"{text}"); + MainClass.InfoLog($"{text}"); if (text != prevMenuText) { Speak(text, interrupt); @@ -66,7 +68,7 @@ namespace stardew_access.ScreenReader public void SayWithChatChecker(string text, bool interrupt) { if (text == null) return; - MainClass.GetMonitor().Log($"{text}"); + MainClass.InfoLog($"{text}"); if (text != prevChatText) { Speak(text, interrupt); @@ -77,7 +79,7 @@ namespace stardew_access.ScreenReader public void SayWithTileQuery(string text, int x, int y, bool interrupt) { if (text == null) return; - MainClass.GetMonitor().Log($"{text}"); + MainClass.InfoLog($"{text}"); if (text != prevTextTile) { Speak(text, interrupt); diff --git a/stardew-access/ScreenReader/ScreenReaderMac_old.cs b/stardew-access/ScreenReader/ScreenReaderMac_old.cs index bc9ec0d..b387874 100644 --- a/stardew-access/ScreenReader/ScreenReaderMac_old.cs +++ b/stardew-access/ScreenReader/ScreenReaderMac_old.cs @@ -19,26 +19,26 @@ namespace stardew_access.ScreenReader public void InitializeScreenReader() { - MainClass.GetMonitor().Log("Screen reader initialized"); + MainClass.InfoLog("Screen reader initialized"); Speak("Mac screen reader ready", true); } public void CloseScreenReader() { - MainClass.GetMonitor().Log("Screen reader closed"); + MainClass.InfoLog("Screen reader closed"); } public void Say(string text, bool interrupt) { if (text == null) return; - MainClass.GetMonitor().Log($"{text}"); + MainClass.InfoLog($"{text}"); Speak(text, interrupt); } public void SayWithChecker(string text, bool interrupt) { if (text == null) return; - MainClass.GetMonitor().Log($"{text}"); + MainClass.InfoLog($"{text}"); if (text != prevText) { Speak(text, interrupt); prevText = text; @@ -48,7 +48,7 @@ namespace stardew_access.ScreenReader public void SayWithMenuChecker(string text, bool interrupt) { if (text == null) return; - MainClass.GetMonitor().Log($"{text}"); + MainClass.InfoLog($"{text}"); if (text != prevMenuText) { Speak(text, interrupt); prevMenuText = text; @@ -58,7 +58,7 @@ namespace stardew_access.ScreenReader public void SayWithChatChecker(string text, bool interrupt) { if (text == null) return; - MainClass.GetMonitor().Log($"{text}"); + MainClass.InfoLog($"{text}"); if (text != prevChatText) { Speak(text, interrupt); prevChatText = text; @@ -68,7 +68,7 @@ namespace stardew_access.ScreenReader public void SayWithTileQuery(string text, int x, int y, bool interrupt) { if (text == null) return; - MainClass.GetMonitor().Log($"{text}"); + MainClass.InfoLog($"{text}"); if (text != prevTextTile) { Speak(text, interrupt); prevTextTile = text; diff --git a/stardew-access/ScreenReader/ScreenReaderWindows.cs b/stardew-access/ScreenReader/ScreenReaderWindows.cs deleted file mode 100644 index d9b2dbc..0000000 --- a/stardew-access/ScreenReader/ScreenReaderWindows.cs +++ /dev/null @@ -1,106 +0,0 @@ -using DavyKager; - -namespace stardew_access.ScreenReader -{ - public class ScreenReaderWindows : IScreenReader - { - private bool isLoaded = false; - public string prevText = "", prevTextTile = " ", prevChatText = "", prevMenuText = ""; - - public string PrevTextTile - { - get { return prevTextTile; } - set { prevTextTile = value; } - } - - public void InitializeScreenReader() - { - MainClass.InfoLog("Initializing Tolk..."); - Tolk.TrySAPI(true); - Tolk.Load(); - - MainClass.InfoLog("Querying for the active screen reader driver..."); - string name = Tolk.DetectScreenReader(); - if (name != null) - { - MainClass.InfoLog($"The active screen reader driver is: {name}"); - isLoaded = true; - } - else - { - MainClass.ErrorLog("None of the supported screen readers is running"); - isLoaded = false; - } - } - - public void CloseScreenReader() - { - if (isLoaded) - { - Tolk.Unload(); - isLoaded = false; - } - } - - public void Say(string text, bool interrupt) - { - if (text == null) - return; - - if (!isLoaded) - return; - - if (!MainClass.Config.TTS) - return; - - if (text.Contains('^')) text = text.Replace('^', '\n'); - - if (Tolk.Output(text, interrupt)) - { - MainClass.DebugLog($"Speaking(interrupt: {interrupt}) = {text}"); - } - else - { - MainClass.ErrorLog($"Failed to output text: {text}"); - } - } - - public void SayWithChecker(string text, bool interrupt) - { - if (prevText != text) - { - prevText = text; - Say(text, interrupt); - } - } - - public void SayWithMenuChecker(string text, bool interrupt) - { - if (prevMenuText != text) - { - prevMenuText = text; - Say(text, interrupt); - } - } - - public void SayWithChatChecker(string text, bool interrupt) - { - if (prevChatText != text) - { - prevChatText = text; - Say(text, interrupt); - } - } - - public void SayWithTileQuery(string text, int x, int y, bool interrupt) - { - string query = $"{text} x:{x} y:{y}"; - - if (prevTextTile != query) - { - prevTextTile = query; - Say(text, interrupt); - } - } - } -}