-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
66 lines (61 loc) · 1.92 KB
/
main.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
import speech_recognition as sr
import pyttsx3
import pywhatkit as kit
import datetime
import wikipedia
import pyjokes
import time
import randfacts
listener = sr.Recognizer()
engine = pyttsx3.init()
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, language='en-US')
command = command.lower()
if 'jarvis' in command:
command = command.replace('jarvis', '')
print(command)
except:
pass
return command
def jarvis():
command = take_command()
if 'play' in command:
song = command.replace('play', '')
talk('playing ' + song)
kit.playonyt(song)
elif 'time' in command:
time = datetime.datetime.now().strftime('%H:%M')
talk('current time is ' + time)
print(time)
elif "today's date" in command:
today = datetime.datetime.now().strftime('%d %m %Y')
talk('The date today is ' + today)
print(time)
elif 'who is' in command:
person = command.replace('who is', '')
info = wikipedia.summary(person, 2)
print(info)
talk(info)
elif 'tell me a fact' or 'fact' or 'say fact' or 'tell me something' in command:
talk(randfacts.get_fact())
elif 'are you single' in command:
talk('I am in a relationship with wifi')
elif 'joke' in command:
talk(pyjokes.get_joke())
elif 'who are you' or 'who created you' or 'who made you' in command:
talk('Hello, I am a virtual assistant, created by Wale')
elif 'insult' or 'roast' in command:
talk('you are a worm')
else:
talk('Please say the command again.')
if __name__ == "__main__":
while True and take_command() != "goodbye":
jarvis()
time.sleep(15)