-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpro_vir.py
More file actions
67 lines (50 loc) · 2.08 KB
/
pro_vir.py
File metadata and controls
67 lines (50 loc) · 2.08 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import speech_recognition as sr
import pyttsx3
import webbrowser
recognizer = sr.Recognizer()
engine = pyttsx3.init()
def speak(text):
engine.say(text)
engine.setProperty("rate",150)
engine.setProperty("volume",1.0)
engine.runAndWait()
def processcommand(c):
if "open google" in c.lower():
webbrowser.open("https://google.com")
elif "open facebook" in c.lower():
webbrowser.open("https://facebook.com")
elif "open youtube" in c.lower():
webbrowser.open("https://youtube.com")
elif "open linkedin" in c.lower():
webbrowser.open("https://linkedin.com")
if __name__ == "__main__":
speak("Initalization of jarvis!!")
while True:
r = sr.Recognizer()
print("recognizing!!")
try:
with sr.Microphone() as source:
print("listening!!")
audio = r.listen(source,timeout=2,phrase_time_limit=1)
word = r.recognize_google(audio)
if(word.lower() == "jarvis"):
speak("yess ,sir!!")
elif(word.lower() == "how are you"):
speak("i am fine ,sir")
elif(word.lower() == "exit"):
speak("EXITING FROM THE PROGRAM , GOODBYE!!")
break
with sr.Microphone() as source:
print("jarvis activating!")
audio = r.listen(source)
command = r.recognize_google(audio)
print(f"command resvied: {command}")
processcommand(command)
if("HOW are u" in command):
speak("i am fine ,sir")
except Exception as e:
print("error;{0}".format(e))
except sr.RequestError as e:
# Handle errors from the Google Web Speech API
print(f"JARVIS error: {e}")
speak("There was an issue with the speech recognition service.")