-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
140 lines (120 loc) · 4.55 KB
/
Copy pathmain.py
File metadata and controls
140 lines (120 loc) · 4.55 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
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import speech_recognition as sr
import pyttsx3
import pywhatkit
import datetime
import wikipedia
import pyjokes
import os
from time import strftime
from tkinter import *
print('Say something...')
listener = sr.Recognizer()
engine = pyttsx3.init()
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[1].id)
def CommandsList():
'''show the command to which voice assistant is registered with'''
os.startfile('')
def talk(text):
engine.say(text)
engine.runAndWait()
def take_command():
try:
with sr.Microphone() as source:
print('listening....')
voice = listener.listen(source)
command = listener.recognize_google(voice)
command = command.lower()
if 'alexa' in command:
command = command.replace('alexa', '')
print(command)
except:
pass
return command
def run_alexa():
command = take_command()
print(command)
if 'play' in command:
song = command.replace('play', '')
talk('playing' + song)
pywhatkit.playonyt(song)
elif 'hello' in command:
day_time = int(strftime('%H'))
if day_time < 12:
talk("""
Hello. Good Morning
I am Alexa and I am your personal voice assistant, Please give a command or say "help me" and I will tell you what all I can do for you.
""")
elif 12 <= day_time < 18:
talk("""
Hello. Good Afternoon
I am Alexa and I am your personal voice assistant, Please give a command or say "help me" and I will tell you what all I can do for you.
""")
else:
talk("""
Hello. Good evening
I am Alexa and I am your personal voice assistant, Please give a command or say "help me" and I will tell you what all I can do for you.
""")
elif 'time' in command:
time = datetime.datetime.now().strftime('%I:%M %p')
print(time)
talk('Current time is ' + time)
elif 'who is' in command:
person = command.replace('who is', '')
info = wikipedia.summary(person, 1)
print(info)
talk(info)
elif 'date' in command:
talk('Sorry,I have a headache')
elif 'are you single' in command:
talk('Im married to the idea of helping people')
elif 'joke' in command:
talk(pyjokes.get_joke())
elif 'help me' in command:
talk("""
You can use these commands and I'll help you out:
1. To wake up the Assistant we use the word 'Alexa'
2. Play 'name of the song/ Artist':Plays a song on youtube
3. time : Current system time
4. Tell a joke/another joke : Says a random dad joke.
5. who is : Tells you a summary of who the person is on wikipedia
6. Open: Launches an system application
7. Ask it anything
""")
elif 'open' in command:
talk('Opening Settings')
os.startfile('C:\Windows\System32\control.exe')
elif 'launch chrome' in command:
talk("Opening chrome")
os.startfile('C:\ProgramData\Microsoft\Windows\Start Menu\Programs')
elif 'notepad' in command:
talk('Opening notepad')
os.startfile('C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Accessories')
elif 'paint' in command:
talk("Opening Microsoft paint....")
os.startfile('C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Accessories')
else:
talk('Come again?')
while True:
run_alexa()
# tkinter code
root = Tk()
# Create the menubar
menubar = Menu(root)
root.config(menu=menubar)
#Create Submenu
subMenu = Menu(menubar, tearoff=0)
menubar.add_cascade(label='Help', menu=subMenu)
subMenu.add_command(label='Commands List', command=CommandsList)
subMenu = Menu(menubar, tearoff=0)
menubar.add_cascade(label='Settings',menu=subMenu)
root.geometry("{}x{}+{}+{}".format(745, 360, int(root.winfo_screenwidth() / 2 - 745 / 2),
int(root.winfo_screenheight() / 2 - 360 / 2)))
root.resizable(0,0)
root.title("Alexa")
root.iconbitmap(r'icon.ico')
root.configure(bg='#000080')
Photo = PhotoImage(file='mic.png')
btn = Button(root, image=Photo, borderwidth=0, activebackground='#2c4557', bg='#000080', command=run_alexa)
btn.place(x=330, y=280)
root.mainloop()