├── README.md ├── main.py └── notes.txt /README.md: -------------------------------------------------------------------------------- 1 | # VirtualAssistant 2 | 3 | This is a program I developed using the python programming language, 4 | It is called Samaritan, Samaritan is a virtual assistant currently tested on Windows systems. 5 | he is able to take commands and give back responses, which makes her to more interactive, 6 | It is able to fetch real time data from the internet and give feedback. 7 | 8 | ## To run it, install all the required libraries and also fetch the required API keys from the specific sites to get the full functionality. 9 | 10 | developed by larymak. 11 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | import pyttsx3 #pip install pyttsx3 2 | import datetime 3 | import pyaudio #pipwin install pyaudio 4 | import speech_recognition as sr #pip install SpeechRecognition 5 | import wikipedia #pip install wikipedia 6 | import webbrowser 7 | import os 8 | import smtplib 9 | import psutil 10 | import pyjokes 11 | import pyautogui 12 | import random 13 | import requests 14 | from pprint import pprint 15 | #pip install pprint 16 | 17 | 18 | MASTER = "Hillary" 19 | print("Initializing Samaritan...") 20 | engine = pyttsx3.init('sapi5') 21 | voices = engine.getProperty('voices') 22 | engine.setProperty('voice', voices[0].id) 23 | 24 | 25 | def speak(audio): 26 | engine.say(audio) 27 | engine.runAndWait() 28 | 29 | def time(): 30 | Time = datetime.datetime.now().strftime("%H:%M:%S") 31 | speak('The current time is') 32 | speak(Time) 33 | 34 | def date(): 35 | year = datetime.datetime.now().year 36 | month = datetime.datetime.now().month 37 | date = datetime.datetime.now().day 38 | speak('The Current date is') 39 | speak(date) 40 | speak(month) 41 | speak(year) 42 | 43 | def wishme(): 44 | speak("Welcome back sir!") 45 | #speak("the current time is") 46 | time() 47 | #speak("it's the") 48 | date() 49 | hour = datetime.datetime.now().hour 50 | if hour >= 0 and hour<12: 51 | speak("Good Morning" + MASTER) 52 | elif hour >=12 and hour<18: 53 | speak("Good Afternoon" + MASTER) 54 | elif hour >=18 and hour <24: 55 | speak("Good evening" + MASTER) 56 | else: 57 | speak("Good Night" + MASTER) 58 | speak("Samaritan at your service. Please tell me how can i help you?") 59 | 60 | def takeCommand(): 61 | r = sr.Recognizer() 62 | with sr.Microphone() as source: 63 | print("Listening...") 64 | r.pause_threshold = 1 65 | audio = r.listen(source) 66 | try: 67 | print("Recognizing...") 68 | query = r.recognize_google(audio, language='en-US') 69 | print(f"user said: {query}\n") 70 | except Exception as e: 71 | print(e) 72 | speak("Say that again please...") 73 | return "None" 74 | 75 | return query 76 | 77 | def sendEmail(to, content): 78 | server = smtplib.SMTP('smtp.gmail.com', 587) 79 | server.ehlo() 80 | server.starttls() 81 | server.login('yormail@gmail.com', 'zxcvbnm,./123') 82 | server.sendmail("sender@gmail.com", to, content) 83 | server.close() 84 | 85 | def cpu(): 86 | usage = str(psutil.cpu_percent()) 87 | speak('CPU is at'+usage) 88 | 89 | """battery = psutil.sensors_battery() 90 | speak('Battery is at') 91 | speak(battery.percent)""" 92 | 93 | def joke(): 94 | speak(pyjokes.get_joke()) 95 | 96 | def screenshot(): 97 | img = pyautogui.screenshot() 98 | img.save('C:/Users/Tech/Desktop/Assets/screenshot.png') 99 | 100 | def who_am_i(): 101 | speak('You are ' + MASTER + ', a brilliant person. I love you!') 102 | 103 | def where_born(): 104 | speak('I was created by a magician named Hillary, in Nairobi, the magical land of Kenya.') 105 | 106 | def how_are_you(): 107 | speak('I am fine, thank you. How can help you Sir?') 108 | 109 | #speak('Initializing Samaritan...') 110 | #wishme() 111 | #query = takeCommand() 112 | 113 | 114 | if __name__ == "__main__": 115 | wishme() 116 | 117 | while True: 118 | query = takeCommand().lower() 119 | 120 | if 'time' in query: 121 | time() 122 | 123 | elif 'date' in query: 124 | date() 125 | 126 | elif 'who am i' in query: 127 | who_am_i() 128 | 129 | elif 'where were you born' in query: 130 | where_born() 131 | 132 | elif 'how are you' in query: 133 | how_are_you() 134 | 135 | elif 'wikipedia' in query.lower(): 136 | speak('searching wikipedia...') 137 | query = query.replace("wikipedia", "") 138 | results = wikipedia.summary(query, sentences=3) 139 | speak('According to Wikipedia...') 140 | print(results) 141 | speak(results) 142 | 143 | elif 'send email' in query.lower(): 144 | try: 145 | speak('What should I send...') 146 | content = takeCommand() 147 | speak('Who is the Receiver Sir?') 148 | receiver = input("Enter Receiver's Email :") 149 | to = receiver 150 | sendEmail(to, content) 151 | speak('Email sent Successfuly') 152 | 153 | except Exception as e: 154 | print(e) 155 | speak('Unable to send Email') 156 | 157 | elif 'search in chrome' in query.lower(): 158 | speak('What should I Search?') 159 | chrome_path = 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s' 160 | 161 | search = takeCommand().lower() 162 | webbrowser.get(chrome_path).open_new_tab(search+'.com') 163 | 164 | elif 'search youtube' in query: 165 | speak('What should I Search?') 166 | search_term = takeCommand().lower() 167 | speak("Opening YOUTUBE!") 168 | webbrowser.open('https://www.youtube.com/results?search_query='+search_term) 169 | 170 | elif 'weather details' in query: #weathermap Api 171 | speak('Which City Sir!') 172 | weather_up = takeCommand().lower() 173 | speak('Getting Weather Update for '+ weather_up) 174 | url = 'https://api.openweathermap.org/data/2.5/weather?q={}&appid={API KEY}&units=metric'.format(weather_up) 175 | 176 | resi = requests.get(url) 177 | data = resi.json() 178 | temp = data['main']['temp'], 179 | wind_speed = data['wind']['speed'], 180 | latitude = data['coord']['lat'], 181 | longitude = data['coord']['lon'], 182 | description = data['weather'][0]['description'] 183 | 184 | speak('Temperature is at: {} degree celcius'.format(temp)) 185 | speak('Wind Speed is at: {} Micro Seconds'.format(wind_speed)) 186 | speak('Latitude is : {}'.format(latitude)) 187 | speak('Longitude is : {}'.format(longitude)) 188 | speak('Clouds Status are : {}'.format(description)) 189 | #update = webbrowser.open('https://api.openweathermap.org/data/2.5/weather?q={}&appid={API KEY}'.format(weather_up)) 190 | 191 | elif 'open google' in query: 192 | speak('What should I Search?') 193 | search_term = takeCommand().lower() 194 | speak('Searching...') 195 | url = 'google.com' 196 | chrome_path = 'C:\Program Files (x86)\Google\Chrome\Application/chrome.exe %s' 197 | webbrowser.open('https://www.google.com/search?q='+search_term) 198 | 199 | elif 'open github' in query: 200 | speak('Opening Github Sir!') 201 | search_term = takeCommand().lower() 202 | speak('Opening your Account Sir!') 203 | url = 'github.com' 204 | webbrowser.open('https://www.github.com/youraccount') 205 | 206 | elif 'cpu' in query: 207 | cpu() 208 | 209 | elif 'joke' in query: 210 | joke() 211 | 212 | elif 'go offline' in query: 213 | speak('Going Offline Sir!') 214 | quit() 215 | 216 | elif 'open word' in query: 217 | speak('Opening MS Word....') 218 | ms_word = r'C:/ProgramData/Microsoft/Windows/Start Menu/Programs/Microsoft Office/WINWORD.EXE' 219 | os.startfile(ms_word) 220 | 221 | elif 'open downloads' in query: 222 | speak('Opening Downloads....') 223 | downloads = r'C:/Users/Tech/Downloads' 224 | os.startfile(downloads) 225 | 226 | elif 'open python' in query: 227 | speak('Opening PyCharm....') 228 | pycharm = r'C:/Program Files/JetBrains/PyCharm Community Edition 2020.1.2/bin/pycharm64.exe' 229 | os.startfile(pycharm) 230 | 231 | elif 'open visual code' in query: 232 | speak('Opening Visual Code....') 233 | pycharm = r'C:/Program Files/Microsoft VS Code/Code.exe' 234 | os.startfile(pycharm) 235 | 236 | elif 'write a note' in query: 237 | speak("What Should i write, Sir?") 238 | notes = takeCommand() 239 | file = open('notes.txt','w') 240 | speak("Sir Should I include Date and Time?") 241 | ans = takeCommand() 242 | if 'yes' in ans or 'sure' in ans: 243 | strTime = datetime.datetime.now().strftime("%H:%M:%S") 244 | file.write(strTime) 245 | file.write(':-') 246 | file.write(notes) 247 | speak("Done taking Notes, Sir!") 248 | else: 249 | file.write(notes) 250 | 251 | elif 'show notes' in query: 252 | speak('Showing Notes') 253 | file = open('notes.txt','r') 254 | print(file.read()) 255 | speak(file.read()) 256 | 257 | elif 'screenshot' in query: 258 | screenshot() 259 | 260 | elif 'play music' in query: 261 | songs_dir = 'E:/Bongo' 262 | music = os.listdir(songs_dir) 263 | speak('What should I play?') 264 | speak('Select a number......') 265 | answer = takeCommand().lower() 266 | while('number' not in answer and answer != 'random' and answer != 'you choose'): 267 | speak('I could not understand you. Please Come up again') 268 | answer = takeCommand().lower() 269 | if 'number' in answer: 270 | no = int(answer.replace('number','')) 271 | elif 'random' or 'you choose' in answer: 272 | no = random.randint(1,100) 273 | os.startfile(os.path.join(songs_dir,music[no])) 274 | 275 | elif 'who are you' in query: 276 | speak("I am Samaritan, The Smart Assistant of Hillary, Developed to help him around with his work and makes his life easier with his machine") 277 | -------------------------------------------------------------------------------- /notes.txt: -------------------------------------------------------------------------------- 1 | thank you for your service --------------------------------------------------------------------------------