Categories We Write About

Build a voice command file launcher

Here’s a simple Python-based Voice Command File Launcher using speech_recognition and os modules. This script allows you to open specific files or apps using voice commands.

Features:

  • Recognizes your voice input via microphone

  • Matches keywords with a predefined dictionary of file paths

  • Launches files or applications accordingly


Prerequisites

Install required packages:

bash
pip install SpeechRecognition pyaudio

If pyaudio fails to install, use:
pip install pipwin
pipwin install pyaudio


Python Script

python
import speech_recognition as sr import os import time # Define a dictionary with voice commands and their corresponding file paths commands = { "open chrome": r"C:Program FilesGoogleChromeApplicationchrome.exe", "open word": r"C:Program FilesMicrosoft OfficerootOffice16WINWORD.EXE", "open excel": r"C:Program FilesMicrosoft OfficerootOffice16EXCEL.EXE", "open notepad": r"C:Windowssystem32notepad.exe", "open vscode": r"C:UsersYourUsernameAppDataLocalProgramsMicrosoft VS CodeCode.exe" } def recognize_speech(): r = sr.Recognizer() with sr.Microphone() as source: print("Listening for command...") audio = r.listen(source) try: command = r.recognize_google(audio).lower() print(f"Recognized command: {command}") return command except sr.UnknownValueError: print("Could not understand audio") return None except sr.RequestError: print("Could not request results from Google Speech Recognition service") return None def execute_command(command): for key in commands: if key in command: print(f"Executing: {key}") os.startfile(commands[key]) return True print("Command not recognized.") return False if __name__ == "__main__": print("Voice Command File Launcher Initialized") time.sleep(1) while True: cmd = recognize_speech() if cmd: if "exit" in cmd or "quit" in cmd: print("Exiting...") break execute_command(cmd)

Customization

  • Replace file paths with the actual path on your system.

  • Add more entries to the commands dictionary.

  • Add a GUI or logging if needed for advanced use.

This script listens continuously until you say “exit” or “quit”.

Let me know if you want a version with a graphical interface or support for more complex commands.

Share This Page:

Enter your email below to join The Palos Publishing Company Email List

We respect your email privacy

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Categories We Write About