macro
This directory contains files that implement a macro recording and playback system. It allows users to record sequences of voice commands and replay them later with a single command.
The core functionality is split between the Talon file macro.talon and the Python file macro.py.
macro.talon
This file defines the voice commands that users will use to interact with the macro system. It provides commands for:
- Starting and stopping macro recording (
macro record,macro stop). - Playing back a macro, either the last recorded or a named one (
macro play [{user.saved_macros}]). - Copying a macro to the clipboard as a Talon command, either the last recorded or a named one (
macro copy [{user.saved_macros}],macro copy as <user.text>). - Saving a macro with a name (
macro save as <user.text>). - Listing and closing the list of saved macros (
macro list,macro list close).
macro.py
This file contains the Python implementation of the macro system. It defines the actions that are performed when the voice commands in macro.talon are spoken. Key parts of this file are:
Actionsclass: This class defines all the actions themacro.talonfile uses, including recording, stopping, saving, playing, and copying macros.macro_record(): Initializes a new macro recording by resetting themacrolist and sets therecordingflag toTrue.macro_stop(): Stops the macro recording and removes the "stop", "play", or "save" command from the macro.macro_save(name): Saves the current macro under the specifiednameand updates a list of saved macros calleduser.saved_macros.macro_play(name): Plays back the macro by usingactions.mimic()to simulate the recorded voice commands. If anameis specified it will load the macro saved under that name, otherwise it will replay the last recorded command.macro_copy(name): Copies the macro as a series ofmimic()commands to the clipboard as text that can be pasted into a Talon file. If anameis specified, it will load that macro. If anameis not specified, it will copy the most recently recorded macro.macro_append_command(words): Appends the command that was just uttered to themacrolist.speech_system.register("pre:phrase", fn): Registers a callback functionfnthat is called before a phrase is processed. This function is responsible for listening to what was spoken while recording and passing it on to themacro_append_commandfunction to be added to the currentmacrolist.macro_list_gui(): Creates an imgui interface to display a list of the user's saved macros.
How they work together
The .talon file provides the user interface for the macro functionality, allowing the user to control the macro recording and playback process with voice commands. The .py file handles the logic, state management, and execution.
When a user speaks a command like "macro record," the corresponding action in macro.py is triggered and the system starts recording the user's subsequent voice commands. These commands are stored in the macro list in macro.py. When the user says "macro stop", the recording stops and the macro list contains a series of lists of words that were spoken during the recording.
Commands like "macro play" or "macro save as" then access that list to replay or save them for later use.