-
Notifications
You must be signed in to change notification settings - Fork 0
/
kryptoknite.py
164 lines (118 loc) · 4.67 KB
/
kryptoknite.py
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
import os
import sys
import datetime
import pyttsx3
import speech_recognition as sr
import wikipedia
import wolframalpha
import webbrowser
import smtplib
import random
engine = pyttsx3.init('sapi5')
client = wolframalpha.Client('Get your own key')
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[len(voices) - 2].id)
def talk(audio):
print('KryptoKnite: ' + audio)
engine.say(audio)
engine.runAndWait()
def greetMe():
CurrentHour = int(datetime.datetime.now().hour)
if CurrentHour >= 0 and CurrentHour < 12:
talk('Good Morning!')
elif CurrentHour >= 12 and CurrentHour < 18:
talk('Good Afternoon!')
elif CurrentHour >= 18 and CurrentHour != 0:
talk('Good Evening!')
greetMe()
talk('Hey Buddy, It\'s your assistant KryptoKnite!')
talk('tell me about today?')
def GivenCommand():
k = sr.Recognizer()
with sr.Microphone() as source:
print("Listening...")
k.pause_threshold = 1
audio = k.listen(source)
try:
Input = k.recognize_google(audio, language='en-in')
print('Kunal Dhariwal: ' + Input + '\n')
except sr.UnknownValueError:
talk('Sorry! I didn\'t get that! Try typing it here!')
Input = str(input('Command: '))
return Input
if __name__ == '__main__':
while True:
Input = GivenCommand()
Input = Input.lower()
if 'open google' in Input:
talk('sure')
webbrowser.open('www.google.co.in')
elif 'open gmail' in Input:
talk('sure')
webbrowser.open('www.gmail.com')
elif 'open youtube' in Input:
talk('sure')
webbrowser.open('www.youtube.com')
elif "what\'s up" in Input or 'how are you' in Input:
setReplies = ['Just doing some stuff!', 'I am good!', 'Nice!', 'I am amazing and full of power']
talk(random.choice(setReplies))
elif "who are you" in Input or 'where are you' in Input or 'what are you' in Input:
setReplies = [' I am KryptoKnite', 'In your system', 'I am an example of AI']
talk(random.choice(setReplies))
elif 'email' in Input:
talk('Who is the recipient? ')
recipient = GivenCommand()
if 'me' in recipient:
try:
talk('What should I say? ')
content = GivenCommand()
server = smtplib.SMTP('smtp.gmail.com', 587)
server.ehlo()
server.starttls()
server.login("Your_Username", 'Your_Password')
server.sendmail('Your_Username', "Recipient_Username", content)
server.close()
talk('Email sent!')
except:
talk('Sorry ! I am unable to send your message at this moment!')
elif 'nothing' in Input or 'abort' in Input or 'stop' in Input:
talk('okay')
talk('Bye, have a good day.')
sys.exit()
elif 'hello' in Input:
talk('hey')
elif 'bye' in Input:
talk('Bye, have a great day.')
sys.exit()
elif 'play music' in Input:
music_folder = 'C:\\Users\\Public\\Music\\'
music = ['friends']
random_music = music_folder + random.choice(music) + '.mp3'
os.system(random_music)
talk('Okay, here is your music! Enjoy!')
elif 'show images' in Input:
images_folder = 'C:\\Users\\Public\\Pictures\\'
images = ['kunal']
random_images = images_folder + random.choice(images) + '.jpeg'
os.system(random_images)
talk('Okay, here are your images! Have Fun!')
else:
Input = Input
talk('Searching...')
try:
try:
res = client.Input(Input)
outputs = next(res.outputs).text
talk('Alpha says')
talk('Gotcha')
talk(outputs)
except:
outputs = wikipedia.summary(Input, sentences=3)
talk('Gotcha')
talk('Wikipedia says')
talk(outputs)
except:
talk("searching on google for " + Input)
say = Input.replace(' ', '+')
webbrowser.open('https://www.google.co.in/search?q=' + Input)
talk('Next Command! Please!')