spyoungtech / voice-commander

cross-platform voice-activation hooks and keyboard macros
MIT License
6 stars 0 forks source link

voice-commander

An application for defining macros and triggers using voice commands and hotkeys. Inspired by the popular commercial software VoiceAttack.

Requires Python 3.12+

This is a major rewrite of a pre-existing project. If you're looking for the older version of this software, see the pre-rewrite tag (or the now-yanked 0.0.1a version on PyPI).

Installation

Via pip

To install, ideally in a virtualenv, use pip:

pip install voice-commander

This software also requires that you have AutoHotkey installed. You can either install AutoHotkey to a default location or, alternatively, install the ahk-binary package in your virtualenv:

pip install ahk-binary

Windows executable

Coming soon.

Usage

The basic primitives include profiles, triggers, actions, and conditions.

Basic example

You can define and run profiles in Python code.

from voice_commander.profile import Profile
from voice_commander.triggers import *
from voice_commander.actions import *

profile = Profile("myprofile")

# triggers when any of these phrases are spoken
# You can add as many phrases as you want
trigger = VoiceTrigger('lower landing gear', 'retract landing gear')
# When the above trigger activates from a voice command, presses the "l" button (bound in-game to landing gear toggle)
action = AHKPressAction("l")
trigger.add_action(action)  # you can add multiple actions if you want. Here, we're just adding one action.
profile.add_trigger(trigger)

profile.run()

You can also serialize/deserialize profiles to/from JSON.

# save the profile to the present working directory
profile.save_json(dirname='.', filename='myprofile.vcp.json')  # "vcp" means "Voice Commander Profile"
from voice_commander.profile import load_profile
# easily load profiles from JSON
profile = load_profile('./myprofile.vcp.json')
profile.run()

You may also edit and run JSON files which represent the complete profile directly. The above example produces a JSON file substantially as follows:

{
    "configuration": {
        "profile_name": "myprofile",
        "schema_version": "0",
        "triggers": [
            {
                "trigger_type": "voice_commander.triggers.VoiceTrigger",
                "trigger_config": {
                    "*trigger_phrases": [
                        "lower landing gear",
                        "retract landing gear"
                    ]
                },
                "actions": [
                    {
                        "action_type": "voice_commander.actions.AHKPressAction",
                        "action_config": {
                            "key": "l"
                        }
                    }
                ]
            }
        ]
    }
}

JSON5 is also supported. More formats may be supported in the future.

You can run profiles from these files directly from the command line:

python -m voice_commander run-profile --profile-file ./myprofile.vcp.json

Full documentation coming soon.

Extending voice commander

voice-commander is being built with extension in mind. We don't have much to share here just yet, but you can check out the voice-commander-elite project, which is an extension intended to provide special functionality for players of the game Elite Dangerous. It is currently being used as a guinea pig for future extensions. voice-commander-elite may also give you ideas of the kinds of other extensions that may be possible.

Status

This project is in early stages of development, but is ready for use. Efforts will be made to keep existing profile schemas compatible with (or convertable to) any future schema versions, though the Python API is likely to have some breaking changes, at least while we're getting off the ground.

Current Limitations

Some of the notable limitations of this software are as follows: