Jun 27, 2024
Initialize Recognizer and TTS Engine:
recognizer = sr.Recognizer()
engine = pyttsx3.init()
Define Speak Function: Uses TTS to speak text aloud.
def speak(text):
engine.say(text)
engine.runAndWait()
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.')
Install Libraries:
pip install pyautogui Pillow pytesseract openai
Dependency Setup (on Windows):
Initialize PyAutoGUI for Screenshot:
import pyautogui
screenshot = pyautogui.screenshot()
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()
Automate Reply in WhatsApp:
pyautogui.typewrite(reply)
pyautogui.press('enter')