DumbassStuff-VoiceCommandsAPI icon

VoiceCommandsAPI

Provides a framework for other mods to create and manage voice commands. Uses Vosk for offline, high-performance speech recognition.

Last updated a month ago
Total downloads 77
Total rating 0 
Categories Libraries
Dependency string DumbassStuff-VoiceCommandsAPI-1.0.0
Dependants 0 other packages depend on this package

This mod requires the following mods to function

BepInEx-BepInExPack-5.4.2100 icon
BepInEx-BepInExPack

BepInEx pack for Mono Unity games. Preconfigured and ready to use.

Preferred version: 5.4.2100

README


VoiceCommandsAPI for Lethal Company

A powerful, lightweight, and offline voice command framework for Lethal Company modders.

This mod provides a simple yet flexible API that allows other mods to easily implement voice commands using the high-performance Vosk offline speech recognition engine.

Key Features

  • 100% Offline: All voice processing happens on your computer. No internet connection is required, ensuring maximum performance and privacy.
  • Easy-to-Use API: Designed for developers to integrate in minutes. Register simple commands or complex patterns with minimal code.
  • High Performance: Built on the Vosk engine, which is optimized for low-latency, real-time recognition.
  • Flexible Matching: Supports both exact phrase matching (e.g., "open door") and flexible pattern matching (e.g., matching any phrase that starts with "tell the ship...").
  • Dependency-Based: Acts as a central framework, so multiple mods can use voice commands without conflicting.

For Players

What This Mod Does

This mod is a dependency or framework. On its own, it does nothing. Its purpose is to provide the underlying technology for other mods that want to use voice commands.

You only need to install this mod if another mod lists it as a requirement.

Installation

  1. Install BepInEx: Make sure you have the BepInExPack installed.
  2. Install the API: Use a mod manager like r2modman or the Thunderstore Mod Manager to install VoiceCommandsAPI. Alternatively, you can download it from the releases page and place the VoiceCommandsAPI.dll and vosk-model-small-en-us-0.15 folder into your BepInEx/plugins directory.

For Developers

How to Use the API

Integrating voice commands into your mod is straightforward.

1. Add the Dependency

First, add VoiceCommandsAPI to your manifest.json dependencies:

{
  "name": "YourCoolMod",
  "version_number": "1.0.0",
  "website_url": "",
  "description": "My mod that uses voice commands!",
  "dependencies": [
    "BepInEx-BepInExPack-5.4.2100",
    "DumbassStuff-VoiceCommandsAPI-1.0.0" 
  ]
}

Next, add a reference to the VoiceCommandsAPI.dll in your C# project.

2. Access the CommandManager

The API is accessed through the CommandManager singleton instance.

using VoiceCommandsAPI.API;

3. Registering Commands

You can register commands in your plugin's Awake() method. There are two primary ways to register a command.

A) Registering an Exact Phrase

Use this for simple commands where the user must say the exact phrase. The matching is case-insensitive.

// In your plugin's Awake() method

// The phrase to listen for (will be converted to lowercase)
string commandPhrase = "open the blast doors";

// The action to execute when the phrase is recognized
Action commandAction = () => {
    HangarShipDoor.Instance.PlayDoorAnimation(true);
    MyLogger.LogInfo("Voice command 'open the blast doors' executed!");
};

// Register the command
CommandManager.Instance.RegisterCommand(commandPhrase, commandAction);

B) Registering a Pattern

Use this for more complex commands where you want to match a pattern or extract values from the speech. The handler receives the recognized text as a parameter.

// In your plugin's Awake() method

// 1. The matcher function: returns true if the text matches your pattern.
// In this example, we check if the command starts with "scan for ".
Func<string, bool> matcher = (text) => text.StartsWith("scan for ");

// 2. The handler function: contains the logic to execute.
// It receives the full recognized text.
Action<string> handler = (text) => {
    // Extract the target from the recognized text
    string target = text.Substring("scan for ".Length);
    MyLogger.LogInfo($"Executing scan for target: {target}");
    
    // Add your custom logic here, e.g., ping a specific scrap item
};

// Register the pattern
CommandManager.Instance.RegisterPattern(matcher, handler);

4. Subscribing to Events (Optional)

The CommandManager also exposes events for more advanced use cases, such as providing UI feedback.

// Get feedback on partially recognized text (e.g., for a "Listening..." UI)
CommandManager.Instance.OnPartialText += (text) => {
    MyUI.ShowSubtitle(text);
};

// Know when any command is successfully matched and executed
CommandManager.Instance.OnCommandRecognized += (text) => {
    MyUI.ShowSuccessPing();
};

// Know when speech was recognized but didn't match any command
CommandManager.Instance.OnCommandNotMatched += (text) => {
    MyUI.ShowFailurePing();
};

How It Works

The API safely hooks into the game's Dissonance audio pipeline to capture the local player's microphone input. This audio is resampled to the 16kHz format required by Vosk and processed in real-time. The results are then checked against registered commands from other mods.

Credits

This project would not be possible without the incredible Vosk-API. Please consider supporting their work. This readme was written by AI bc im lazy as fuck, sue me :)