-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainFile.py
More file actions
88 lines (73 loc) · 2.47 KB
/
MainFile.py
File metadata and controls
88 lines (73 loc) · 2.47 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import speech_recognition as sr
import pyttsx3,os,random,time,webbrowser,wikipedia
from tkinter import *
engine = pyttsx3.init()
voices = engine.setProperty("rate",115)
def speak(audio):
engine.say(audio)
engine.runAndWait()
def hear():
r = sr.Recognizer()
with sr.Microphone() as source:
print("Speak:")
audio = r.listen(source)
try:
audio = r.recognize_google(audio, language='en-in')
print("You said ",audio)
return audio
except:
speak("could not understand your audio, retry")
return "default"
def music():
mus ="C:\\Users\\ASUS\\Music\\Playlists"
fil = os.listdir(mus)
m = random.choice(fil)
os.startfile(os.path.join(mus,m))
exit()
def work(inp):
if "sara" in inp or "your name"in inp:
speak("Hey iam Sara iam happy to help you Dear")
elif 'music' in inp:
speak("playing music ")
speak("thank you have a nice day")
music()
exit()
elif "wind up" in inp or "exit" in inp:
speak("thank you have a nice day")
exit()
elif "facebook" in inp:
webbrowser.open('facebook.com')
speak("Iam happy to help you thankyou.. enjoy your moment with facebook ")
exit()
elif "default" in inp:
pass
# speak("could you say it again")
elif ("search in google" in inp)or("search" in inp):
speak("opening webpage")
webbrowser.open(inp)
else :
try:
speak(wikipedia.summary(inp, sentences=3))
except:
webbrowser.open(inp)
def handle_button_start(event):
speak("speak")
inp=hear().lower()
work(inp)
speak("End of the Result")
def handle_button_press(event):
window.destroy()
speak("hai i am sara iam a chatbot happy to assist you")
window=Tk()
window.title("Voice Assistant")
window.minsize(100,50)
window.maxsize(200,100)
window.geometry("300x150+550+250")
text1=Label(window,text="Click start")
text1.pack()
button1=Button(window, text="Start")
button1.bind("<Button-1>",handle_button_start)
button1.pack()
button2 =Button(window, text=" Exit ",command=window.quit)
button2.pack()
window.mainloop()