-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpyassis
123 lines (111 loc) · 4.29 KB
/
pyassis
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# -*- coding: utf-8 -*-
"""
Created on Wed Jan 26 19:24:33 2022
@author Sharanya
"""
from tkinter import *
import webbrowser as wb
import speech_recognition as sr
import pyttsx3 as pt
import pyjokes
import time
import pywhatkit
import datetime
import wikipedia
root=Tk()
root.title("PYTHON ASSISTANT")
def assist():
text=pt.init()
r=sr.Recognizer()
text.say("hello. i am luca. i am your virtual assistant ")
text.say("what can i do for you")
text.runAndWait()
with sr.Microphone() as source:
audio=r.listen(source)
try:
ans=r.recognize_google(audio)
if "name" in ans.lower():
text.say("your name is amulya")
text.runAndWait()
elif "search" in ans.lower():
a=ans.split()
a.remove('search')
a.remove('for')
if 'can' and 'you' in a:
a.remove('can')
a.remove('you')
else:
pass
n=''
for i in range(len(a)):
n=n+str(a[i])+" "
wb.open_new('https://www.google.com/search?q='+n+
'&ei=dozzYb2sGJ7H4-EP0uWeoA8&ved='+
'0ahUKEwi9v6aQ6NP1AhWe4zgGHdKyB_'+
'QQ4dUDCA4&uact=5&oq=flowers&gs_lcp='+
'Cgdnd3Mtd2l6EAMyCAgAELEDEJECMggIABCxAx'+
'CRAjIICAAQgAQQsQMyCAguELEDEJECMgUIABCABDIF'+
'CAAQgAQyBQgAEIAEMgUIABCABDIKCAAQgAQQsQMQCjI'+
'ICAAQgAQQsQM6BwgAELADEAo6CwgAELADEAcQChAeSg'+
'QIQRgBSgQIRhgAUNkDWNkDYL8JaAFwAHgAgAFqiAFq'+
'kgEDMC4xmAEAoAEByAEGwAEB&sclient=gws-wiz')
text.say("searching"+n)
text.runAndWait()
elif "joke" in ans.lower():
My_joke = pyjokes.get_joke(language="en", category="neutral")
time.sleep(1)
print("The joke is:")
text.say(My_joke)
text.runAndWait()
print(My_joke)
elif "song" in ans.lower():
text.say("which song do you want to play")
text.runAndWait()
with sr.Microphone() as source:
audio=r.listen(source)
try:
song=r.recognize_google(audio)
pywhatkit.playonyt(song)
text.say("paying"+song+"on youtube")
text.runAndWait()
except():
text.say("could not recognise the song name")
text.runAndWait()
elif "video" in ans.lower():
text.say("which video do you want to play")
text.runAndWait()
with sr.Microphone() as source:
audio=r.listen(source)
try:
video=r.recognize_google(audio)
pywhatkit.playonyt(video)
text.say("paying"+video+"on youtube")
text.runAndWait()
except():
text.say("could not recognise the song name")
text.runAndWait()
elif "time" in ans.lower():
time=datetime.datetime.now().strftime('%H:%M')
text.say("current time is "+time)
text.runAndWait()
elif "who is " in ans.lower() or "what is " in ans.lower():
*a,b=ans.split()
info=wikipedia.summary(b,)
text.say(info)
text.runAndWait()
elif "bye" in ans.lower():
text.say("bye")
text.say("have a nice day")
text.runAndWait()
else:
text.say("this is out of my reach. sorry")
text.runAndWait()
except:
text.say("sorry could not recognize your voice")
text.runAndWait()
#GUI
b1=Button(root,text="speak ",command=assist,fg="blue",bg="yellow")
b1.pack()
b2=Button(root,text="close",command=root.destroy,bg="red")
b2.pack()
root.mainloop()