Update to upstream 6e5f9365f0
				
					
				
			Remove windows screen reader (probably not a good idea to have separate access forks, but this works for now.) Send rate when initialising speech (TODO: expose this via a config parameter)
This commit is contained in:
		@@ -6,16 +6,9 @@ namespace stardew_access.ScreenReader
 | 
				
			|||||||
    {
 | 
					    {
 | 
				
			||||||
        public IScreenReader Initialize()
 | 
					        public IScreenReader Initialize()
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            IScreenReader ScreenReader = new ScreenReaderWindows(); // Default is windows
 | 
					            IScreenReader ScreenReader = new ScreenReaderMac(); // Mac by default
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
 | 
					if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                ScreenReaderWindows screenReaderWindows = new ScreenReaderWindows();
 | 
					 | 
				
			||||||
                screenReaderWindows.InitializeScreenReader();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                ScreenReader = screenReaderWindows;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
 | 
					 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                ScreenReaderLinux screenReaderLinux = new ScreenReaderLinux();
 | 
					                ScreenReaderLinux screenReaderLinux = new ScreenReaderLinux();
 | 
				
			||||||
                screenReaderLinux.InitializeScreenReader();
 | 
					                screenReaderLinux.InitializeScreenReader();
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -11,40 +11,42 @@ namespace stardew_access.ScreenReader
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        public string PrevTextTile
 | 
					        public string PrevTextTile
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            get;
 | 
					            get { return prevTextTile; }
 | 
				
			||||||
            set;
 | 
					            set { prevTextTile = value; }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        public string prevText = "", prevTextTile = " ", prevChatText = "", prevMenuText = "";
 | 
					        public string prevText = "", prevTextTile = " ", prevChatText = "", prevMenuText = "";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        public void InitializeScreenReader()
 | 
					        public void InitializeScreenReader()
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            MainClass.GetMonitor().Log("Screen reader initialized");
 | 
					            MainClass.InfoLog("Screen reader initialized");
 | 
				
			||||||
            _speakProcess = new Process();
 | 
					            _speakProcess = new Process();
 | 
				
			||||||
            _speakProcess.StartInfo.FileName = "mac";
 | 
					            _speakProcess.StartInfo.FileName = "mac";
 | 
				
			||||||
            _speakProcess.StartInfo.Verb = "mac";
 | 
					            _speakProcess.StartInfo.Verb = "mac";
 | 
				
			||||||
            _speakProcess.StartInfo.RedirectStandardInput = true;
 | 
					            _speakProcess.StartInfo.RedirectStandardInput = true;
 | 
				
			||||||
            _speakProcess.Start();
 | 
					            _speakProcess.Start();
 | 
				
			||||||
 | 
											// set rate (probably should be done through a config parameter)
 | 
				
			||||||
 | 
					_speakProcess.StandardInput.WriteLine("r600");
 | 
				
			||||||
            Speak("Mac screen reader ready", true);
 | 
					            Speak("Mac screen reader ready", true);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        public void CloseScreenReader()
 | 
					        public void CloseScreenReader()
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            MainClass.GetMonitor().Log("Screen reader closed");
 | 
					            MainClass.InfoLog("Screen reader closed");
 | 
				
			||||||
            _speakProcess.Kill();
 | 
					            _speakProcess.Kill();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        public void Say(string text, bool interrupt)
 | 
					        public void Say(string text, bool interrupt)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            if (text == null) return;
 | 
					            if (text == null) return;
 | 
				
			||||||
            MainClass.GetMonitor().Log($"{text}");
 | 
					            MainClass.InfoLog($"{text}");
 | 
				
			||||||
            Speak(text, interrupt);
 | 
					            Speak(text, interrupt);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        public void SayWithChecker(string text, bool interrupt)
 | 
					        public void SayWithChecker(string text, bool interrupt)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            if (text == null) return;
 | 
					            if (text == null) return;
 | 
				
			||||||
            MainClass.GetMonitor().Log($"{text}");
 | 
					            MainClass.InfoLog($"{text}");
 | 
				
			||||||
            if (text != prevText)
 | 
					            if (text != prevText)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                Speak(text, interrupt);
 | 
					                Speak(text, interrupt);
 | 
				
			||||||
@@ -55,7 +57,7 @@ namespace stardew_access.ScreenReader
 | 
				
			|||||||
        public void SayWithMenuChecker(string text, bool interrupt)
 | 
					        public void SayWithMenuChecker(string text, bool interrupt)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            if (text == null) return;
 | 
					            if (text == null) return;
 | 
				
			||||||
            MainClass.GetMonitor().Log($"{text}");
 | 
					            MainClass.InfoLog($"{text}");
 | 
				
			||||||
            if (text != prevMenuText)
 | 
					            if (text != prevMenuText)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                Speak(text, interrupt);
 | 
					                Speak(text, interrupt);
 | 
				
			||||||
@@ -66,7 +68,7 @@ namespace stardew_access.ScreenReader
 | 
				
			|||||||
        public void SayWithChatChecker(string text, bool interrupt)
 | 
					        public void SayWithChatChecker(string text, bool interrupt)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            if (text == null) return;
 | 
					            if (text == null) return;
 | 
				
			||||||
            MainClass.GetMonitor().Log($"{text}");
 | 
					            MainClass.InfoLog($"{text}");
 | 
				
			||||||
            if (text != prevChatText)
 | 
					            if (text != prevChatText)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                Speak(text, interrupt);
 | 
					                Speak(text, interrupt);
 | 
				
			||||||
@@ -77,7 +79,7 @@ namespace stardew_access.ScreenReader
 | 
				
			|||||||
        public void SayWithTileQuery(string text, int x, int y, bool interrupt)
 | 
					        public void SayWithTileQuery(string text, int x, int y, bool interrupt)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            if (text == null) return;
 | 
					            if (text == null) return;
 | 
				
			||||||
            MainClass.GetMonitor().Log($"{text}");
 | 
					            MainClass.InfoLog($"{text}");
 | 
				
			||||||
            if (text != prevTextTile)
 | 
					            if (text != prevTextTile)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                Speak(text, interrupt);
 | 
					                Speak(text, interrupt);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -19,26 +19,26 @@ namespace stardew_access.ScreenReader
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        public void InitializeScreenReader()
 | 
					        public void InitializeScreenReader()
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            MainClass.GetMonitor().Log("Screen reader initialized");
 | 
					            MainClass.InfoLog("Screen reader initialized");
 | 
				
			||||||
            Speak("Mac screen reader ready", true);
 | 
					            Speak("Mac screen reader ready", true);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        public void CloseScreenReader()
 | 
					        public void CloseScreenReader()
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            MainClass.GetMonitor().Log("Screen reader closed");
 | 
					            MainClass.InfoLog("Screen reader closed");
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        public void Say(string text, bool interrupt)
 | 
					        public void Say(string text, bool interrupt)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            if (text == null) return;
 | 
					            if (text == null) return;
 | 
				
			||||||
            MainClass.GetMonitor().Log($"{text}");
 | 
					            MainClass.InfoLog($"{text}");
 | 
				
			||||||
            Speak(text, interrupt);
 | 
					            Speak(text, interrupt);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        public void SayWithChecker(string text, bool interrupt)
 | 
					        public void SayWithChecker(string text, bool interrupt)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            if (text == null) return;
 | 
					            if (text == null) return;
 | 
				
			||||||
            MainClass.GetMonitor().Log($"{text}");
 | 
					            MainClass.InfoLog($"{text}");
 | 
				
			||||||
            if (text != prevText) {
 | 
					            if (text != prevText) {
 | 
				
			||||||
                Speak(text, interrupt);
 | 
					                Speak(text, interrupt);
 | 
				
			||||||
                prevText = text;
 | 
					                prevText = text;
 | 
				
			||||||
@@ -48,7 +48,7 @@ namespace stardew_access.ScreenReader
 | 
				
			|||||||
        public void SayWithMenuChecker(string text, bool interrupt)
 | 
					        public void SayWithMenuChecker(string text, bool interrupt)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            if (text == null) return;
 | 
					            if (text == null) return;
 | 
				
			||||||
            MainClass.GetMonitor().Log($"{text}");
 | 
					            MainClass.InfoLog($"{text}");
 | 
				
			||||||
            if (text != prevMenuText) {
 | 
					            if (text != prevMenuText) {
 | 
				
			||||||
                Speak(text, interrupt);
 | 
					                Speak(text, interrupt);
 | 
				
			||||||
                prevMenuText = text;
 | 
					                prevMenuText = text;
 | 
				
			||||||
@@ -58,7 +58,7 @@ namespace stardew_access.ScreenReader
 | 
				
			|||||||
        public void SayWithChatChecker(string text, bool interrupt)
 | 
					        public void SayWithChatChecker(string text, bool interrupt)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            if (text == null) return;
 | 
					            if (text == null) return;
 | 
				
			||||||
            MainClass.GetMonitor().Log($"{text}");
 | 
					            MainClass.InfoLog($"{text}");
 | 
				
			||||||
            if (text != prevChatText) {
 | 
					            if (text != prevChatText) {
 | 
				
			||||||
                Speak(text, interrupt);
 | 
					                Speak(text, interrupt);
 | 
				
			||||||
                prevChatText = text;
 | 
					                prevChatText = text;
 | 
				
			||||||
@@ -68,7 +68,7 @@ namespace stardew_access.ScreenReader
 | 
				
			|||||||
        public void SayWithTileQuery(string text, int x, int y, bool interrupt)
 | 
					        public void SayWithTileQuery(string text, int x, int y, bool interrupt)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            if (text == null) return;
 | 
					            if (text == null) return;
 | 
				
			||||||
            MainClass.GetMonitor().Log($"{text}");
 | 
					            MainClass.InfoLog($"{text}");
 | 
				
			||||||
            if (text != prevTextTile) {
 | 
					            if (text != prevTextTile) {
 | 
				
			||||||
                Speak(text, interrupt);
 | 
					                Speak(text, interrupt);
 | 
				
			||||||
                prevTextTile = text;
 | 
					                prevTextTile = text;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -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);
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
		Reference in New Issue
	
	Block a user