The Palos Publishing Company

Follow Us On The X Platform @PalosPublishing
Categories We Write About

Write a voice-controlled automation tool

Here’s a basic implementation of a voice-controlled automation tool using Python. This example uses the speech_recognition library to recognize voice commands and perform simple automation tasks like opening websites or applications.

python
import speech_recognition as sr import webbrowser import os import time # Define command actions def execute_command(command): command = command.lower() if "open youtube" in command: webbrowser.open("https://www.youtube.com") print("Opening YouTube...") elif "open google" in command: webbrowser.open("https://www.google.com") print("Opening Google...") elif "open notepad" in command: os.system("notepad.exe") print("Opening Notepad...") elif "what time is it" in command: print("Current time is:", time.strftime("%I:%M %p")) elif "exit" in command or "quit" in command: print("Exiting voice assistant.") return False else: print("Sorry, I didn't understand that command.") return True # Initialize the recognizer recognizer = sr.Recognizer() def listen_command(): with sr.Microphone() as source: print("Listening for your command...") recognizer.adjust_for_ambient_noise(source) audio = recognizer.listen(source) try: command = recognizer.recognize_google(audio) print("You said:", command) return command except sr.UnknownValueError: print("Sorry, I could not understand the audio.") except sr.RequestError: print("Could not request results from the speech recognition service.") return "" # Main loop if __name__ == "__main__": print("Voice-controlled automation tool started. Say 'exit' to quit.") running = True while running: command = listen_command() if command: running = execute_command(command)

Requirements:

Install dependencies with pip:

bash
pip install SpeechRecognition pyaudio

If you encounter issues with pyaudio installation, on Windows use:

bash
pip install pipwin pipwin install pyaudio

Notes:

  • This is a basic framework. You can add more sophisticated commands and NLP for natural interaction.

  • It uses Google’s Web Speech API (requires internet).

  • To run on macOS/Linux, replace notepad.exe with any available text editor (like gedit or open -a TextEdit).

Let me know if you want this tool integrated with smart devices, system automation frameworks, or a GUI.

Share this Page your favorite way: Click any app below to share.

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

We respect your email privacy

Categories We Write About