A lightweight voice command service that enables hands-free coding by listening for voice commands and simulating keyboard shortcuts. Perfect for use with AI coding assistants like Cursor or with dictation services.
This tool enables you to control your coding environment with your voice, letting you execute common actions like pressing Enter or accepting code changes (Command+Enter) without touching your keyboard.
- Simple: Easy to set up and use
- Lightweight: Minimal resource usage
- Extensible: Easy to add new commands
- Compatible: Works with macOS and most code editors
- Voice-activated keyboard shortcuts
- Simple terminal-based interface
- Global command for easy activation
- Audio feedback for command recognition
- Works alongside dictation services
Currently supported voice commands:
- Say "enter" to press the Enter key
- Say "run it" or "run that" to press Command+Enter
- Say "exit" or "stop" to quit the service
- macOS (for sound effects and terminal integration)
- Python 3.x
- Required Python packages:
speechrecognition- For voice recognitionpyautogui- For keyboard simulationpyaudio- For audio input processingpocketsphinx- As fallback recognizer
Note on Windows Compatibility: This tool was developed and tested on macOS. While the core functionality should work on Windows, some features like sound effects and terminal integration may require modifications. Windows-specific contributions are welcome!
git clone https://github.com/your-username/voice-mode.git
cd voice-mode# Install PortAudio (required for PyAudio)
brew install portaudio
# Install required Python packages
pip install speechrecognition pyautogui pyaudio pocketsphinx# Run the alias setup script
./voice_mode_config/add_alias.sh
# Reload your shell configuration
source ~/.zshrc# Using the alias (from anywhere)
voice
# OR from the project directory
./start_voice_commands.sh
# OR from the voice_mode_config directory
cd voice_mode_config
python voice_commander.pyThe voice command service works especially well with AI coding assistants like Cursor:
- Start the voice service in a terminal:
voice - Open your AI coding assistant
- When the assistant suggests code changes:
- Say "run it" to accept the changes (triggers Command+Enter)
- When you need a new line:
- Say "enter" to press Enter
- Continue coding with voice commands as needed
When using with dictation services:
- Use dictation for writing code
- Pause dictation temporarily when you need to use voice commands
- Say your command ("enter" or "run it")
- Resume dictation
To use this tool effectively with macOS built-in dictation:
-
Enable dictation:
- Go to System Preferences > Keyboard > Dictation
- Turn dictation ON
- Choose a keyboard shortcut to toggle dictation (default is press Fn key twice)
-
Configure dictation settings:
- Go to System Preferences > Accessibility > Voice Control
- Check "Enable Voice Control"
- Adjust microphone and language settings as needed
-
Using together with Voice Mode:
- Start Voice Mode in a terminal window
- In your code editor, toggle dictation ON using your keyboard shortcut
- Dictate your code normally
- When you need to execute a command, toggle dictation OFF momentarily
- Say your voice command ("enter" or "run it")
- Toggle dictation back ON to continue coding
This workflow allows seamless switching between dictating code and executing commands.
voice_commander.py- Main Python script that listens for voice commandsstart_voice_commands.sh- Shell script to start the servicetest_mic.py- Utility script to test microphone detectionadd_alias.sh- Script to add the 'voice' command alias
If the service doesn't detect your voice:
- Run
python test_mic.pyto test your microphone - Check if your microphone is selected and working in System Preferences
- Try adjusting the
energy_thresholdvalue invoice_commander.py(lower value = more sensitive) - Make sure you're speaking clearly and at a normal volume
You can add new commands or modify existing ones by editing the voice_commander.py file:
- Add a new function to simulate the desired keyboard shortcut
- Add the command to the recognition logic in the
listen_for_commandsfunction - Restart the voice service
MIT License
Contributions are welcome! All pull requests will be reviewed by the repository owner before merging.
- Fork the repository
- Create your feature branch:
git checkout -b feature/amazing-feature - Commit your changes:
git commit -m 'Add some amazing feature' - Push to the branch:
git push origin feature/amazing-feature - Open a Pull Request
The repository owner will review your changes and provide feedback before merging.
Built by Will Barksdale V ~ Last Updated: June 13, 2025