Intelligent Personal Assistant
Abstract
Intelligent Personal Assistant is a Python project that uses NLP and automation to create a personal assistant. The application features voice recognition, task management, and a CLI interface, demonstrating best practices in productivity and AI.
Prerequisites
- Python 3.8 or above
- A code editor or IDE
- Basic understanding of NLP and automation
- Required libraries:
speechrecognition
speechrecognition
,pyttsx3
pyttsx3
,gtts
gtts
,schedule
schedule
Before you Start
Install Python and the required libraries:
Install dependencies
pip install SpeechRecognition pyttsx3 gtts schedule
Install dependencies
pip install SpeechRecognition pyttsx3 gtts schedule
Getting Started
Create a Project
- Create a folder named
intelligent-personal-assistant
intelligent-personal-assistant
. - Open the folder in your code editor or IDE.
- Create a file named
intelligent_personal_assistant.py
intelligent_personal_assistant.py
. - Copy the code below into your file.
Write the Code
⚙️ Intelligent Personal Assistant
Intelligent Personal Assistant
import datetime
import webbrowser
class IntelligentPersonalAssistant:
def __init__(self):
pass
def tell_time(self):
now = datetime.datetime.now()
print(f"Current time: {now.strftime('%H:%M:%S')}")
def open_website(self, url):
webbrowser.open(url)
print(f"Opened website: {url}")
def demo(self):
self.tell_time()
self.open_website('https://www.python.org')
if __name__ == "__main__":
print("Intelligent Personal Assistant Demo")
assistant = IntelligentPersonalAssistant()
assistant.demo()
Intelligent Personal Assistant
import datetime
import webbrowser
class IntelligentPersonalAssistant:
def __init__(self):
pass
def tell_time(self):
now = datetime.datetime.now()
print(f"Current time: {now.strftime('%H:%M:%S')}")
def open_website(self, url):
webbrowser.open(url)
print(f"Opened website: {url}")
def demo(self):
self.tell_time()
self.open_website('https://www.python.org')
if __name__ == "__main__":
print("Intelligent Personal Assistant Demo")
assistant = IntelligentPersonalAssistant()
assistant.demo()
Example Usage
Run personal assistant
python intelligent_personal_assistant.py
Run personal assistant
python intelligent_personal_assistant.py
Explanation
Key Features
- Voice Recognition: Listens and processes voice commands.
- Task Management: Manages tasks and reminders.
- Error Handling: Validates inputs and manages exceptions.
- CLI Interface: Interactive command-line usage.
Code Breakdown
- Import Libraries and Setup Assistant
intelligent_personal_assistant.py
import speech_recognition as sr
import pyttsx3
import schedule
import time
intelligent_personal_assistant.py
import speech_recognition as sr
import pyttsx3
import schedule
import time
- Voice Recognition and Task Management Functions
intelligent_personal_assistant.py
def listen_command():
r = sr.Recognizer()
with sr.Microphone() as source:
print("Listening...")
audio = r.listen(source)
try:
command = r.recognize_google(audio)
return command
except Exception as e:
print(f"Error: {e}")
return ""
def speak(text):
engine = pyttsx3.init()
engine.say(text)
engine.runAndWait()
def add_task(task):
print(f"Task added: {task}")
intelligent_personal_assistant.py
def listen_command():
r = sr.Recognizer()
with sr.Microphone() as source:
print("Listening...")
audio = r.listen(source)
try:
command = r.recognize_google(audio)
return command
except Exception as e:
print(f"Error: {e}")
return ""
def speak(text):
engine = pyttsx3.init()
engine.say(text)
engine.runAndWait()
def add_task(task):
print(f"Task added: {task}")
- CLI Interface and Error Handling
intelligent_personal_assistant.py
def main():
print("Intelligent Personal Assistant")
while True:
cmd = input('> ')
if cmd == 'listen':
command = listen_command()
speak(f"You said: {command}")
elif cmd == 'add':
task = input("Task: ")
add_task(task)
elif cmd == 'exit':
break
else:
print("Unknown command. Type 'listen', 'add', or 'exit'.")
if __name__ == "__main__":
main()
intelligent_personal_assistant.py
def main():
print("Intelligent Personal Assistant")
while True:
cmd = input('> ')
if cmd == 'listen':
command = listen_command()
speak(f"You said: {command}")
elif cmd == 'add':
task = input("Task: ")
add_task(task)
elif cmd == 'exit':
break
else:
print("Unknown command. Type 'listen', 'add', or 'exit'.")
if __name__ == "__main__":
main()
Features
- Personal Assistant: Voice recognition and task management
- Modular Design: Separate functions for each task
- Error Handling: Manages invalid inputs and exceptions
- Production-Ready: Scalable and maintainable code
Next Steps
Enhance the project by:
- Integrating with calendar and email APIs
- Supporting advanced NLP models
- Creating a GUI for assistant
- Adding context management
- Unit testing for reliability
Educational Value
This project teaches:
- Productivity: Personal assistant and automation
- Software Design: Modular, maintainable code
- Error Handling: Writing robust Python code
Real-World Applications
- Virtual Assistants
- Productivity Tools
- Smart Home Integration
Conclusion
Intelligent Personal Assistant demonstrates how to build a scalable and intelligent assistant using Python. With modular design and extensibility, this project can be adapted for real-world applications in productivity, smart homes, and more. For more advanced projects, visit Python Central Hub.
Was this page helpful?
Let us know how we did