-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjarvis.py
More file actions
57 lines (51 loc) · 1.77 KB
/
Copy pathjarvis.py
File metadata and controls
57 lines (51 loc) · 1.77 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
# importing pyttsx3
import pyttsx3
# importing speech_recognition
import speech_recognition as sr
# creating take_commands() function which
# can take some audio, Recognize and return
# if there are not any errors
def take_commands():
# initializing speech_recognition
r = sr.Recognizer()
# opening physical microphone of computer
with sr.Microphone() as source:
print('Listening')
r.pause_threshold = 0.7
# storing audio/sound to audio variable
audio = r.listen(source)
try:
print("Recognizing")
# Recognizing audio using google api
Query = r.recognize_google(audio)
print("the query is printed='", Query, "'")
except Exception as e:
print(e)
print("Say that again sir")
# returning none if there are errors
return "None"
# returning audio as text
return Query
# creating Speak() function to giving Speaking power
# to our voice assistant
def Speak(audio):
# initializing pyttsx3 module
engine = pyttsx3.init()
# anything we pass inside engine.say(),
# will be spoken by our voice assistant
engine.say(audio)
engine.runAndWait()
# Driver Code
if __name__ == '__main__':
# using while loop to communicate infinitely
while True:
command = take_commands()
if "exit" in command:
Speak("Sure sir! as your wish, bai")
break
if "insta" in command:
Speak("Best python page on instagram is pythonhub")
if "learn" in command:
Speak("copyassignment website is best to learn python")
if "code" in command:
Speak("You can get this code from copyassignment website")