Repository navigation
Expand file tree
/
Copy pathcode
More file actions
60 lines (54 loc) · 2.23 KB
/
Copy pathcode
File metadata and controls
60 lines (54 loc) · 2.23 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
import speech_recognition as sr #library for speech recognition
import pyttsx3 as pa #for text to speech library
import pywhatkit as pw # for searching things from youtube currently though
import datetime as t # for date ,time etc things like that
import wikipedia as w #for wikipedia search
import pyjokes #for programmers jokes
listener = sr.Recognizer()
engine=pa.init()
voices=engine.getProperty('voices')
engine.setProperty('voice',voices[1].id) #there are two option of voices in it for male =0 and female =1
engine.say ("i am your jerry What can I do for You ?")
engine.runAndWait()
def talk(text):
engine.say (text)
engine.runAndWait() #this command for running the audio in the talk functions
def jerry_command():
try:
with sr.Microphone() as source:#for using microphone as below voice var. for collecting command
print('Listening...')
voice = listener.listen(source)
command = listener.recognize_google(voice)
command = command.lower()
if "jerry" in command: #for taking they always say command
command = command.replace("jerry", "").strip()
talk (command)
print (command)
return command
#else:
# invalid="say my name"
# print(invalid)
# talk(invalid)
#command=""
except Exception as e:
print("Error:", e)
command= "invalid command"
return command
def run_jerry():
command=jerry_command()
if "play" in command: #for playing something from youtube
song=command.replace("play","").strip()
talk("Playing"+song)
pw.playonyt(song)
elif "time" in command:# for telling time
time=t.datetime.now().strftime("%H:%M")
print(time)
talk("Time is :"+time)
elif "search" in command: #for search feature on wiki but it have very less data store. I used it on superstar it work on rajnikant, akshay kumar etc.
person=command.replace("search","").strip()
info=w.summary(person,4)
print (info)
talk (info)
elif "joke" in command: #this gives programmers jokes
talk(pyjokes.get_joke())
run_jerry()