-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
41 lines (34 loc) · 1.13 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import speech_recognition as sr
import pyttsx3
from google.cloud import speech
import webbrowser
from bs4 import BeautifulSoup
import requests
recognizer = sr.Recognizer()
engine = pyttsx3.init()
def speak(text):
engine.say(text)
engine.runAndWait()
def processCommand(c):
if c.lower().startswith('open'):
website = c.lower().split(' ')[1]
response = requests.get(url=f'https://www.google.com/search?q={website}&ln=en')
soup = BeautifulSoup(response.text, 'html.parser')
speak(soup.text)
if __name__ == "__main__" :
speak("Initializing JARVIS...")
while True:
r = sr.Recognizer()
print("Listening...")
try:
with sr.Microphone() as source:
recognizer.adjust_for_ambient_noise(source)
audio = r.listen(source)
# Recognize the speech
text = r.recognize_google(audio)
print("Recognized speech: ", text)
if text.lower() == "jarvis":
speak("Jarvis activated")
processCommand(text)
except sr.RequestError as e:
print("Error; {0}".format(e))