Skip to content

Commit

Permalink
Merge pull request #7 from LoafOrc/1.2.0
Browse files Browse the repository at this point in the history
unregister and full custom listeners
  • Loading branch information
LoafOrc authored Dec 31, 2023
2 parents 49431c6 + 1ba3019 commit 516e69e
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 21 deletions.
Binary file modified Dependencies/LethalSettings.dll
Binary file not shown.
2 changes: 1 addition & 1 deletion Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace VoiceRecognitionAPI {
public class Plugin : BaseUnityPlugin {
public const string modGUID = "me.loaforc.voicerecognitionapi";
public const string modName = "VoiceRecognitionAPI";
public const string modVersion = "1.1.1";
public const string modVersion = "1.2.0";

private static readonly Harmony harmony = new Harmony(modGUID);
internal static Plugin instance;
Expand Down
4 changes: 2 additions & 2 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("VoiceRecognitionAPI")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyDescription("Load Windows Recognition into Lethal Company with a dev friendly implemenation system.")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyCompany("loaforc")]
[assembly: AssemblyProduct("VoiceRecognitionAPI")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")]
Expand Down
34 changes: 25 additions & 9 deletions Voice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,46 @@ public static class Voice {

internal static List<string> phrases = new List<string>();

public static void ListenForPhrase(string phrase, Action<string> callback) {
ListenForPhrase(phrase, DEFAULT_MIN_CONFIDENCE, callback);
public static EventHandler<VoiceRecognitionEventArgs> CustomListenForPhrases(string[] phrases, EventHandler<VoiceRecognitionEventArgs> callback) {
Voice.phrases.AddRange(phrases);
EventHandler<VoiceRecognitionEventArgs> wrapped = (__, args) => {
if (phrases.Contains(args.Message)) {
callback.Invoke(__, args);
}
};
VoiceRecognitionFinishedEvent += wrapped;
return wrapped;
}

public static void ListenForPhrase(string phrase, float minConfidence, Action<string> callback) {
ListenForPhrases(new string[] { phrase }, minConfidence, callback);
public static EventHandler<VoiceRecognitionEventArgs> ListenForPhrase(string phrase, Action<string> callback) {
return ListenForPhrase(phrase, DEFAULT_MIN_CONFIDENCE, callback);
}

public static void ListenForPhrases(string[] phrases, Action<string> callback) {
ListenForPhrases(phrases, DEFAULT_MIN_CONFIDENCE, callback);
public static EventHandler<VoiceRecognitionEventArgs> ListenForPhrase(string phrase, float minConfidence, Action<string> callback) {
return ListenForPhrases(new string[] { phrase }, minConfidence, callback);
}

public static void ListenForPhrases(string[] phrases, float minConfidence, Action<string> callback) {
public static EventHandler<VoiceRecognitionEventArgs> ListenForPhrases(string[] phrases, Action<string> callback) {
return ListenForPhrases(phrases, DEFAULT_MIN_CONFIDENCE, callback);
}

public static EventHandler<VoiceRecognitionEventArgs> ListenForPhrases(string[] phrases, float minConfidence, Action<string> callback) {
if(Plugin.RECOGNITION_SETUP) {
throw new VoiceRecognitionEngineAlreadyStarted("The voice recognition engine was already started. If you are a developer, Make sure to setup your voice recognition patterns in Awake().");
}

Plugin.logger.LogInfo(phrases);
Voice.phrases.AddRange(phrases);
VoiceRecognitionFinishedEvent += (__, args) => {
EventHandler<VoiceRecognitionEventArgs> recCallback = (__, args) => {
if (phrases.Contains(args.Message) && args.Confidence >= minConfidence) {
callback.Invoke(args.Message);
}
};
VoiceRecognitionFinishedEvent += recCallback;
return recCallback;
}

public static void StopListeningForPhrase(EventHandler<VoiceRecognitionEventArgs> callback) {
VoiceRecognitionFinishedEvent -= callback;
}

internal static void VoiceRecognition(RecognizeCompletedEventArgs e) {
Expand Down
16 changes: 9 additions & 7 deletions VoiceRecognitionAPI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<!-- prevent referenced assemblies from being copied to the output folder -->
<Target Name="ClearReferenceCopyLocalPaths" AfterTargets="ResolveAssemblyReferences">
<ItemGroup>
<ReferenceCopyLocalPaths Remove="@(ReferenceCopyLocalPaths)" />
</ItemGroup>
</Target>
<!-- prevent referenced assemblies from being copied to the output folder -->
<Target Name="ClearReferenceCopyLocalPaths" AfterTargets="ResolveAssemblyReferences">
<ItemGroup>
<ReferenceCopyLocalPaths Remove="@(ReferenceCopyLocalPaths)" />
</ItemGroup>
</Target>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
Expand All @@ -40,7 +40,9 @@
<Reference Include="LethalSettings">
<HintPath>Dependencies\LethalSettings.dll</HintPath>
</Reference>
<Reference Include="Unity.TextMeshPro, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null" />
<Reference Include="Unity.TextMeshPro">
<HintPath>$(LethalCompanyPath)\Lethal Company_Data\Managed\Unity.TextMeshPro.dll</HintPath>
</Reference>
<Reference Include="UnityEngine">
<HintPath>$(LethalCompanyPath)\Lethal Company_Data\Managed\UnityEngine.dll</HintPath>
</Reference>
Expand Down
Binary file added build/loaforc-VoiceRecognitionAPI-1.2.0.zip
Binary file not shown.
4 changes: 2 additions & 2 deletions thunderstore.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ schemaVersion = "0.0.1"
[package]
namespace = "loaforc"
name = "VoiceRecognitionAPI"
versionNumber = "1.1.1"
versionNumber = "1.2.0"
description = "Loads Windows Speech recognition into Lethal Company and provides a dev-friendly way of using it."
websiteUrl = "https://github.com/LoafOrc/VoiceRecognitionAPI"
containsNsfwContent = false
[package.dependencies]
BepInEx-BepInExPack = "5.4.2100"
willis81808-LethalSettings = "1.0.2"
willis81808-LethalSettings = "1.2.1"

[build]
icon = "./icon.png"
Expand Down

0 comments on commit 516e69e

Please sign in to comment.