Skip to content

Commit c1d34bb

Browse files
committed
feat: Added simple assistant with basic features.
1 parent 35f2eab commit c1d34bb

File tree

1 file changed

+123
-0
lines changed

1 file changed

+123
-0
lines changed

Simple Assistant/assistant.py

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
import pyttsx3,datetime,os,random,requests
2+
import wikipedia,webbrowser,sys,pywhatkit
3+
import speech_recognition as sr
4+
5+
6+
engine = pyttsx3.init('sapi5')
7+
voices = engine.getProperty("voices")
8+
engine.setProperty('voice',voices[1].id)
9+
10+
11+
# To convdert text into voice
12+
def speak(audio):
13+
engine.say(audio)
14+
print(audio)
15+
engine.runAndWait()
16+
17+
# To convert voice into text
18+
def takecommand():
19+
r = sr.Recognizer()
20+
with sr.Microphone() as source:
21+
print("Listening...")
22+
r.pause_threshold = 1
23+
audio = r.listen(source,timeout=2,phrase_time_limit=5)
24+
25+
try:
26+
print("Recognizing...")
27+
query = r.recognize_google(audio,language='en-in')
28+
except Exception:
29+
speak("Can you please say that again ... ")
30+
return 'none'
31+
return query
32+
33+
# To wish
34+
def wish():
35+
hour = int(datetime.datetime.now().hour)
36+
if hour >=0 and hour<=12:
37+
speak("Good morning Sir")
38+
elif hour>12 and hour<16:
39+
speak("Good afternoon Sir")
40+
elif hour>16 and hour<22:
41+
speak("Good evening Sir")
42+
speak("I am jarvis, Please tell me how can i help you !")
43+
44+
45+
if __name__ == "__main__":
46+
wish()
47+
if 1:
48+
query = takecommand().lower()
49+
50+
if 'open notepad' in query:
51+
npath = 'C:\\Windows\\System32\\notepad.exe'
52+
os.startfile(npath)
53+
speak("Please wait ! While I am opening notepad for you!")
54+
55+
elif "open cmd" in query:
56+
os.system('start cmd')
57+
speak("Opening Command Promte")
58+
59+
elif "play music" in query:
60+
music_dir = 'D:\\Songs'
61+
songs = os.listdir(music_dir)
62+
rd = random.choice(songs)
63+
os.startfile(os.path.join(music_dir,rd))
64+
speak("Playing Music")
65+
66+
elif "ip address" in query:
67+
ip = requests.get("https://api.ipify.org").text
68+
speak(f"Your Ip address is {ip}")
69+
70+
elif 'wikipedia' in query:
71+
speak("Searching in wikipedia")
72+
query = query.replace("wikipedia","")
73+
results = wikipedia.summary(query,sentences=5)
74+
speak(f"according to wikipedia {results}")
75+
76+
elif "open youtube" in query:
77+
webbrowser.open('www.youtube.com/')
78+
79+
elif "open instagram" in query:
80+
webbrowser.open('www.instagram.com/')
81+
82+
elif "open facebook" in query:
83+
webbrowser.open('www.facebook.com/')
84+
85+
elif "open twitter" in query:
86+
webbrowser.open('www.twitter.com/')
87+
88+
elif "open google" in query:
89+
speak('Sir what should i search on google ! ')
90+
varg = takecommand().lower()
91+
webbrowser.open(varg)
92+
93+
# elif 'send message' in query:
94+
# pywhatkit.sendwhatmsg("+919988776655",'Hello I am Jarvis ! How are you Sir ?',18,33,10,True)
95+
96+
# elif 'play song on youtube' in query:
97+
# speak("Which song would you like to play on youtube ? ")
98+
# song = takecommand().lower()
99+
# pywhatkit.playonyt(song)
100+
101+
# elif 'play video' in query:
102+
# speak("Which video would you like to play on youtube ? ")
103+
# vsong = takecommand().lower()
104+
# pywhatkit.playonyt(vsong)
105+
106+
107+
elif 'nothing' in query or 'abort' in query or 'stop' in query:
108+
speak('okay')
109+
speak('Bye Sir, have a good day.')
110+
sys.exit()
111+
112+
elif 'hello' in query:
113+
speak('Hello Sir')
114+
115+
elif 'bye' in query:
116+
speak('Bye Sir, have a good day.')
117+
sys.exit()
118+
119+
120+
elif "what\'s up" in query or 'how are you' in query:
121+
stMsgs = ['Just doing my thing!', 'I am fine!', 'Nice!', 'I am nice and full of energy']
122+
speak(random.choice(stMsgs))
123+

0 commit comments

Comments
 (0)