-
Notifications
You must be signed in to change notification settings - Fork 0
/
ida.py
154 lines (117 loc) · 4.75 KB
/
ida.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
import speech_recognition as sr
import pyttsx3
import datetime
import wikipedia
import webbrowser
import os
import time
import subprocess
import pywhatkit
import pyjokes
print('Loading your personal assistant - IDA')
engine=pyttsx3.init('sapi5')
voices=engine.getProperty('voices')
engine.setProperty('voice',voices[1].id)
def speak(text):
engine.say(text)
engine.runAndWait()
def wishMe():
hour = datetime.datetime.now().hour
if hour>=0 and hour<12:
speak("Hello,Good Morning")
print("Hello,Good Morning")
elif hour>=12 and hour<18:
speak("Hello,Good Afternoon")
print("Hello,Good Afternoon")
else:
speak("Hello,Good Evening")
print("Hello,Good Evening")
def takeCommand():
r = sr.Recognizer()
with sr.Microphone() as source:
print("Listening...")
audio = r.listen(source)
try:
statement = r.recognize_google(audio,language='en-in')
print(f"user said:{statement}\n")
except Exception as e:
speak("Pardon me, please say that again")
return "None"
return statement
speak("Loading your personal assistant IDA")
wishMe()
if __name__ == '__main__':
while True:
speak("Tell me how can I help you now?")
statement = takeCommand().lower()
if statement == 0:
continue
if "good bye" in statement or "ok bye" in statement or "stop" in statement:
speak('your personal assistant IDA is shutting down,Good bye')
print('your personal assistant IDA is shutting down,Good bye')
break
if 'wikipedia' in statement:
speak('Searching Wikipedia...')
statement = statement.replace("wikipedia", "")
results = wikipedia.summary(statement, sentences=3)
speak("According to Wikipedia")
print(results)
speak(results)
elif 'open youtube' in statement:
webbrowser.open_new_tab("https://www.youtube.com")
speak("youtube is open now")
time.sleep(5)
elif 'open google' in statement:
webbrowser.open_new_tab("https://www.google.com")
speak("Google chrome is open now")
time.sleep(5)
elif 'open gmail' in statement:
webbrowser.open_new_tab("gmail.com")
speak("Google Mail open now")
time.sleep(5)
elif 'open notepad' in statement:
name = statement.replace('open', '')
path0 = f"%windir%\\system32\\notepad.exe"
os.system(path0)
elif 'open wordpad' in statement:
name = statement.replace('open', '')
path0 = f"%windir%\\system32\\wordpad.exe"
os.system(path0)
elif 'open word' in statement:
name = statement.replace('open', '')
path0 = f"C:\\Program Files\\Microsoft Office\\root\\Office16\\WINWORD.EXE"
os.system(path0)
elif 'open powerpoint' in statement:
name = statement.replace('open', '')
path0 = f"C:\\Program Files\\Microsoft Office\\root\\Office16\\POWERPNT.EXE"
os.system(path0)
elif 'time' in statement:
strTime=datetime.datetime.now().strftime("%H:%M:%S")
speak(f"the time is {strTime}")
elif 'who are you' in statement or 'what can you do' in statement:
speak('I am IDA your personal assistant. I am programmed to do minor tasks like'
'opening youtube,google chrome,gmail and predict time,')
elif "who made you" in statement or "who created you" in statement or "who discovered you" in statement:
speak("I was built by DK AND MADHU")
print("I was built by DK AND MADHU")
elif 'news' in statement:
news = webbrowser.open_new_tab("https://timesofindia.indiatimes.com/home/headlines")
speak('Here are some headlines from the Times of India,Happy reading')
time.sleep(6)
elif 'play' in statement:
song = statement.replace('play', '')
speak('playing ' + song)
pywhatkit.playonyt(song)
elif 'joke' in statement:
speak(pyjokes.get_joke())
elif 'search' in statement:
statement = statement.replace("search", "")
webbrowser.open_new_tab(statement)
time.sleep(5)
elif "log off" in statement or "sign out" in statement:
speak("Ok , your pc will log off in 10 sec make sure you exit from all applications")
subprocess.call(["shutdown", "/l"])
elif"weather" in statement:
speak("finding the weather")
webbrowser.open_new_tab("https://www.windy.com/?12.900,80.221,5")
time.sleep(3)