Implementing python script

master
Mohammad Shoaib 2022-01-28 19:20:59 +05:30
parent e84d5ab6bf
commit 0492ade55b
8 changed files with 54 additions and 16 deletions

View File

@ -4,8 +4,9 @@ namespace stardew_access
{
internal class CustomCommands
{
internal static void Initialize(IModHelper helper)
internal static void Initialize()
{
IModHelper helper = MainClass.ModHelper;
helper.ConsoleCommands.Add("readtile", "Toggle read tile feature.", (string commmand, string[] args) =>
{

View File

@ -11,7 +11,7 @@ namespace stardew_access
Footstep
}
internal static void Initialize(IModHelper helper)
internal static void Initialize()
{
try
{
@ -54,7 +54,7 @@ namespace stardew_access
}
SoundEffect effect;
string filePath = Path.Combine(helper.DirectoryPath, $"sounds/{soundEffect.Key}.wav");
string filePath = Path.Combine(MainClass.ModHelper.DirectoryPath,"sounds" , $"{soundEffect.Key}.wav");
using (FileStream stream = new(filePath, FileMode.Open))
{
effect = SoundEffect.FromStream(stream);

View File

@ -1,6 +1,6 @@
import libspeechd
import wrapper
speech = libspeechd.Speech
speech = wrapper.Speech
speech.Initialize(self=speech)

View File

@ -1,7 +1,7 @@
import libspeechd
import wrapper
import time
speech = libspeechd.Speech
speech = wrapper.Speech
speech.Initialize(self=speech)

View File

@ -25,6 +25,12 @@ namespace stardew_access
public static Radar radarFeature;
public static ScreenReader screenReader;
private static IModHelper _modHelper;
public static IModHelper ModHelper
{
get{return _modHelper;}
}
/*********
** Public methods
*********/
@ -35,6 +41,7 @@ namespace stardew_access
#region Initializations
monitor = Monitor; // Inititalize monitor
_modHelper = helper;
Game1.options.setGamepadMode("force_on");
@ -45,9 +52,9 @@ namespace stardew_access
screenReader = new ScreenReader();
screenReader.InitializeScreenReader();
CustomSoundEffects.Initialize(helper);
CustomSoundEffects.Initialize();
CustomCommands.Initialize(helper);
CustomCommands.Initialize();
radarFeature = new Radar();

View File

@ -1,17 +1,40 @@
using AccessibleOutput;
using StardewModdingAPI;
using System.Runtime.InteropServices;
using IronPython.Hosting;
namespace stardew_access
{
public class ScreenReader
{
public IAccessibleOutput? screenReader = null;
public dynamic wrapperInstance = null;
public string prevText = "", prevTextTile = " ", prevChatText = "", prevMenuText = "";
/// <summary>Initializes the screen reader.</summary>
public void InitializeScreenReader()
{
MainClass.monitor.Log($"here! {RuntimeInformation.OSDescription}", LogLevel.Debug);
if(RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
MainClass.monitor.Log($"here!", LogLevel.Debug);
//instance of python engine
var engine = Python.CreateEngine();
//reading code from file
var source = engine.CreateScriptSourceFromFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "LinuxSpeech", "wrapper.py"));
var scope = engine.CreateScope();
//executing script in scope
source.Execute(scope);
var wrapper = scope.GetVariable("Speech");
//initializing class
wrapperInstance = engine.Operations.CreateInstance(wrapper);
wrapperInstance.Initialize();
MainClass.monitor.Log($"here!", LogLevel.Debug);
return;
}
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
return;
@ -55,6 +78,12 @@ namespace stardew_access
/// <param name="interrupt">Whether to skip the currently speaking text or not.</param>
public void Say(string text, bool interrupt)
{
if(RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
wrapperInstance.Say(text, interrupt);
return;
}
if (screenReader == null)
return;
@ -73,7 +102,7 @@ namespace stardew_access
if (prevText != text)
{
prevText = text;
screenReader.Speak(text, interrupt);
Say(text, interrupt);
}
}
@ -90,7 +119,7 @@ namespace stardew_access
if (prevMenuText != text)
{
prevMenuText = text;
screenReader.Speak(text, interrupt);
Say(text, interrupt);
}
}
@ -107,7 +136,7 @@ namespace stardew_access
if (prevChatText != text)
{
prevChatText = text;
screenReader.Speak(text, interrupt);
Say(text, interrupt);
}
}
@ -128,7 +157,7 @@ namespace stardew_access
if (prevTextTile != query)
{
prevTextTile = query;
screenReader.Speak(text, interrupt);
Say(text, interrupt);
}
}
}

View File

@ -8,6 +8,7 @@
<LangVersion>preview</LangVersion>
<PlatformTarget>AnyCPU</PlatformTarget>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<RestoreProjectStyle>PackageReference</RestoreProjectStyle>
</PropertyGroup>
<ItemGroup>