-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pluto.py
132 lines (97 loc) · 3.49 KB
/
Pluto.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
from gtts import gTTS
import speech_recognition as sr
import datetime
import wikipedia
import webbrowser
from pygame import mixer
import smtplib
import os
import time
def speak(audio):
print(audio)
text_to_speech = gTTS(text=audio, lang='en-uk')
text_to_speech.save('audio.mp3')
mixer.init()
mixer.music.load("audio.mp3")
mixer.music.play()
time.sleep(len(audio)//10)
def wishMe():
hour = int(datetime.datetime.now().hour)
if hour>=0 and hour<12:
speak("Good Morning!")
elif hour>=12 and hour<18:
speak("Good Afternoon!")
else:
speak("Good Evening!")
speak("I am PLUTO. Please tell me how may I help you?")
def takeCommand():
r = sr.Recognizer()
with sr.Microphone() as source:
print("Listening...")
r.pause_threshold = 1
r.adjust_for_ambient_noise(source)
audio = r.listen(source)
try:
print("Recognizing...")
command = r.recognize_google(audio, language='en-in')
print(f"User said: {command}\n")
time.sleep(2)
except sr.UnknownValueError:
print('Your last command couldn\'t be heard')
command = takeCommand()
return command
def sendEmail(to, content):
server = smtplib.SMTP('smtp.gmail.com', 587)
server.ehlo()
server.starttls()
server.login('[email protected]', 'your-password')
server.sendmail('[email protected]', to, content)
server.close()
if __name__ == "__main__":
wishMe()
while True:
command = takeCommand().lower()
if 'hello' in command:
speak('Hello! I am PLUTO. How can I help you?')
elif "what can you do" in command:
speak("I can search things, play music, open websites, send email, search for your query, and many more....")
elif 'who are you' in command:
speak('I am your Virtual Assistant...')
elif 'wikipedia' in command:
speak('Searching Wikipedia...')
command = command.replace("wikipedia", "")
results = wikipedia.summary(command, sentences=2)
speak("According to Wikipedia")
print(results)
speak(results)
elif 'open wikipedia' in command:
webbrowser.open("wikipedia.com")
elif 'open youtube' in command:
webbrowser.open("youtube.com")
elif 'open google' in command:
webbrowser.open("google.com")
elif 'open stackoverflow' in command:
webbrowser.open("stackoverflow.com")
elif 'play music' in command:
music_dir = '/home/reeha/Music'
songs = os.listdir(music_dir)
print(songs)
os.path.join(music_dir, songs[0])
elif 'the time' in command:
strTime = datetime.datetime.now().strftime("%H:%M:%S")
speak(f"The time is {strTime}")
elif 'email to' in command:
try:
speak("What should I say?")
content = takeCommand()
to = command.replace("email to ","")
sendEmail(to, content)
speak("Email has been sent!")
except Exception as e:
print(e)
speak("error while sending email...")
elif 'bye' in command or 'quit' in command:
speak("I hope you like my assistance... Have a nice day!")
break
elif "repeat" in command or "speak" in command:
speak(command)