microphone_selection
This directory contains a utility plugin designed to streamline microphone management inside Talon. It provides an interactive graphical user interface (GUI) and voice commands to dynamically view and switch between available microphone inputs.
The plugin consists of two key files:
- microphone_selection.py – Implements the core logic, querying the host system's audio devices, managing the selection state, and rendering the interactive GUI.
- microphone_selection.talon – Exposes voice commands that trigger the GUI or directly select a microphone.
How It Works
The plugin interfaces directly with Talon's internal audio API and the cross-platform audio library cubeb to manage the audio hardware context.
Device Discovery and Filtering
In microphone_selection.py, the plugin instantiates a cubeb.Context() to list the machine's recording inputs.
To ensure a clean user experience:
* The system-default option ("System Default") and a disable option ("None") are prepended to the selection list to mirror Talon's native menu.
* On Windows, the list of devices is filtered to ensure only currently active/connected microphones are shown (dev.state == cubeb.DeviceState.ENABLED). This prevents the UI from becoming cluttered with disconnected historical devices.
* The plugin registers a listener callback on the hardware context ("devices_changed"). If you plug in a new USB headset or unplug a microphone, the device list updates immediately without requiring a restart or manual refresh.
The Graphical Interface (IMGUI)
An interactive, floating Talon imgui window is used to display the available options. When toggled open, this GUI lists each microphone next to an index number.
Users can either: 1. Click the button associated with a microphone in the GUI list. 2. Use the voice commands mapped to select a specific device by its index.
Voice Commands
The microphone_selection.talon file links spoken phrases to the action definitions declared in the Python script:
microphone show: Callsuser.microphone_selection_toggle(), which updates the device list and reveals the IMGUI window.microphone close: Closes the interface.microphone pick <number_small>: Directly activates a microphone by its list index (e.g., "microphone pick two"). Once selected, the script triggers Talon's nativeactions.sound.set_microphone()to switch audio inputs and notifies the user with a system toast notification.