Python Projects: Jarvis and WhatsApp Bot

Jul 16, 2024

Lecture on Python Projects: Jarvis and WhatsApp Bot Projects

Jarvis Project

Overview

  • Creating a virtual assistant like Alexa/Google Home
  • Using Python libraries and APIs
  • Speech recognition, Text-to-Speech, and OpenAI integration

Setting Up Environment

  • Create virtual environment: venv
  • Install necessary packages:
    • pip install speechrecognition pyaudio ttsx3 webbrowser setuptools

Initializing Jarvis

  • Import necessary modules: speech_recognition, pyttsx3, webbrowser
  • Create recognizer object: recognizer = sr.Recognizer()
  • Initialize TTXS engine: engine = pyttsx3.init()
  • Define speak function
    def speak(text):
        engine.say(text)
        engine.runAndWait()
    
  • Main loop to listen wake-word 'Jarvis'
    while True:
        # Listen for 'Jarvis'
        with sr.Microphone() as source:
            # Your code to capture audio and process further
            # Listen for command and process
    

Listening and Recognizing Commands

  • Setting recognizer with Google
    if command.lower() == 'jarvis':
        listen for specific commands
        process commands
    

Performing Actions

  • Open Google, Facebook, YouTube, LinkedIn through webbrowser.open
  • Play specific songs using music_library dictionary
    • Example: music_library['song name'] = 'url'
  • Use OpenAI for custom responses
    • Setting client, generating responses & text-to-speech

WhatsApp Bot Project

Overview

  • Automate WhatsApp message replies using a bot
  • Python automation with pyautogui, piperclip, and OpenAI API

Setting Up Environment

  • Create virtual environment
  • Install necessary packages:
    • pip install pyautogui piperclip openai

Automating WhatsApp

  • Locate and copy message content using pyautogui
  • Parse content and generate a context-based response using OpenAI API
  • Example: content = pyautogui.locateOnScreen('screen.png')

OpenAI Integration

  • Generate responses based on chat history
    client = openai.ApiClient(api_key='YOUR_API_KEY')
    response = client.completion.create(
        prompt='Your conversation content',
        max_tokens=100
    )
    response_text = response.choices[0].text.strip()
    

Sending Reply

  • Using pyautogui to copy response to clipboard and send in WhatsApp
    pyautogui.write(response_text)
    pyautogui.press('enter')
    

Continuous Automation

  • Run in a loop to continuously read and respond to new messages
    while True:
        # Check for new messages and respond
    

Enhancements and Improvisations

  • Fine-tuning recognition and commands processing
  • Adding new functionalities such as handling different URLs
  • Improving efficiency using better libraries or optimizing the code

Concluding Notes

  • Integration of new modules and understanding APIs for advanced features
  • Using Python to create impactful and practical applications

Additional Tips for Project Implementation

GitHub Version Control

  • Utilize GitHub to push and manage your projects
  • Helps in showcasing your work to potential recruiters

Job Search Tips

  • Be active on LinkedIn and ensure professional profiling
  • Send personalized job application emails

Recommended Learning Resources

  • Explore further libraries: MediaPipe, OpenCV, Django, Flask
  • Books: Python for Data Science, Hands-on Machine Learning with Scikit-Learn and Tensorflow