πŸ¦ΎπŸ“ž

Creating Jarvis and WhatsApp Bot using Python

Jun 27, 2024

Lecture: Creating Jarvis and WhatsApp Bot using Python πŸ¦ΎπŸ“ž

Jarvis - Virtual Assistant

Tools and Libraries Used

  1. speech_recognition: For speech recognition
  2. pyttsx3: For text-to-speech conversion
  3. webbrowser: For web actions (e.g., opening Google, YouTube)

Steps and Code Highlights

  1. Initialize Recognizer and TTS Engine:

    recognizer = sr.Recognizer() engine = pyttsx3.init()
  2. Define Speak Function: Uses TTS to speak text aloud.

    def speak(text): engine.say(text) engine.runAndWait()
  3. Listening for Wake Word: Listens for 'Jarvis'.

    while True: with sr.Microphone() as source: print('Listening...') audio = recognizer.listen(source) try: command = recognizer.recognize_google(audio).lower() if 'jarvis' in command: speak('Yes, how can I help you?') # further code to recognize commands except sr.UnknownValueError: speak('Sorry, I did not get that.')

WhatsApp Bot

Tools and Libraries Used

  1. pyautogui: For GUI automation
  2. Pillow (PIL): For image processing
  3. pytesseract: For OCR (Optical Character Recognition)
  4. OpenAI GPT-3 API: For generating responses

Example Setup

  1. Install Libraries:

    pip install pyautogui Pillow pytesseract openai
  2. Dependency Setup (on Windows):

Steps and Code Highlights

  1. Initialize PyAutoGUI for Screenshot:

    import pyautogui screenshot = pyautogui.screenshot()
  2. Read Chat and Generate Response:

    import pytesseract import openai pytesseract.pytesseract.tesseract_cmd = r'<path-to-tesseract-executable>' openai.api_key = 'YOUR_OPENAI_API_KEY' # Capture, OCR and ask GPT-3 chat_text = pytesseract.image_to_string(screenshot) response = openai.Completion.create( engine='text-davinci-003', prompt=chat_text, max_tokens=150 ) reply = response.choices[0].text.strip()
  3. Automate Reply in WhatsApp:

    pyautogui.typewrite(reply) pyautogui.press('enter')