This Python script creates a voice-activated virtual assistant that can perform various tasks such as opening websites, playing songs, providing the current time, and even generating responses using OpenAI’s GPT-3 language model.
- Voice Recognition: The assistant uses the SpeechRecognition library to recognize spoken commands.
- Text-to-Speech: It utilizes the pyttsx3 library to provide spoken responses in a customizable voice.
- Web and App Control: You can command the assistant to open specific websites or applications.
*by specific I mean those stored in the nameofsites python file - Music & Video Playback: You can instruct the assistant to play songs/videos from a predefined list.
*Audio/video files should be downloaded on the system. Then add the name and path of the file to be played to the list in namesofsites file. - Time Display: Ask the assistant for the current time, and it will respond with the current time.
- AI-Powered Responses: By saying “using AI” followed by a prompt, the assistant can generate responses using OpenAI’s GPT-3 text generation model.
- Python 3 installed on your system.
- pyAudio should be installed. (install it from https://www.lfd.uci.edu/~gohlke/pythonlibs/)
- Required Python libraries, including speech_recognition, pyttsx3, webbrowser, os, and openai.
- Access to an OpenAI API key for generating AI-powered responses.
- Though you need to pay for openAI’s responses as per the guidlines of the company.
- Run the python file using any compiler.
- The assistant will greet you and wait for your voice command.
- Speak your command clearly, and the assistant will process it accordingly.
- To exit the program, say “no” when asked if you want any other help.
- For now the number of commands is limited.
- some of the common commands are:
- “what’s the time now?”
- “tell me a joke”
- “open {file/app/website name}”
- “play {video/audio name}”
- “using AI, {prompt for openAI}”
- “using AI, …” is the most flexible command as it returns the query from openAI servers.
- For any audio/video playing, take the another file, i.e., namesofsites and add the name and its address in the “songs_or_videos” list.
- For website/app opening, add the name of the website/app and its url/local address in the “sites_or_apps” list.
- If the zira_id doesn’t work for you or you want to change the voice, find the compatible voice ID’s in your pc using:
voices = pyttsx3.init().getProperty('voices') for voice in voices: print(f"Voice ID: {voice.id}, Name: {voice.name}")
- You can customize the voice accent used by modifying the zira_id variable.
- Careful with changing the voice ID; change as mentioned.
- Add or remove websites and songs in the “sites_or_apps” and “songs_or_videos” lists, respectively, to expand or modify the assistant’s capabilities.
- Be cautious with your OpenAI API key usage to avoid rate limit errors.
- Ensure that you have the necessary voices and language packs installed for text-to-speech functionality.
- The project uses the SpeechRecognition, pyttsx3, and OpenAI libraries.
- Voice responses are generated using OpenAI’s GPT-3.
- You can take the help of CodeWithHarry’s Video in the initial developement, thanks to him I was able to solve some queries!
Feel free to customize and expand upon this code to create your own voice-activated virtual assistant!