├── SnapShot.png ├── News.py ├── Weather.py ├── Youtube.py ├── README.md ├── Wikipedia.py ├── Email.py └── Basic Assistant.py /SnapShot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/1marufbillah/Basic-Virtual-AI-Assistant/HEAD/SnapShot.png -------------------------------------------------------------------------------- /News.py: -------------------------------------------------------------------------------- 1 | import requests 2 | from API import * 3 | 4 | apiAddress = "https://newsapi.org/v2/top-headlines?country=us&apiKey=" + NewsAPI 5 | json_Data = requests.get(apiAddress).json() 6 | 7 | ar = [] 8 | 9 | 10 | def news(): 11 | for i in range(3): 12 | ar.append("Headline " + str(i + 1) + ", " + json_Data["articles"][i]["title"] + ".") 13 | 14 | return ar 15 | 16 | # array = news() 17 | # print(array) 18 | -------------------------------------------------------------------------------- /Weather.py: -------------------------------------------------------------------------------- 1 | import requests 2 | from API import * 3 | 4 | apiAddress = "http://api.openweathermap.org/data/2.5/weather?q=Bogra,BD&appid=" + WeatherAPI 5 | Json_Data = requests.get(apiAddress).json() 6 | 7 | 8 | def temperature(): 9 | temp = round(Json_Data["main"]["temp"] - 273, 1) 10 | return temp 11 | 12 | 13 | def description(): 14 | des = Json_Data["weather"][0]["description"] 15 | return des 16 | 17 | 18 | # print(temperature()) 19 | # print(description()) 20 | -------------------------------------------------------------------------------- /Youtube.py: -------------------------------------------------------------------------------- 1 | from selenium import webdriver 2 | 3 | 4 | class youtube: 5 | def __init__(self): 6 | self.driver = webdriver.Chrome(executable_path='path/chromedriver.exe') 7 | 8 | def play(self, query): 9 | self.query = query 10 | self.driver.get(url="https://www.youtube.com/results?search_query=" + query) 11 | video = self.driver.find_element_by_xpath('//*[@id="video-title"]/yt-formatted-string') 12 | video.click() 13 | # 14 | # assist = youtube() 15 | # assist.play('blood sweat') 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![@1marufbillah](https://user-images.githubusercontent.com/75558710/157602837-cb0c77c5-60d6-4d6c-b5e6-1fbc85dd0860.jpg) 2 | 3 | # Basic Vitrual AI Assistant 4 | virtual assistant, also called AI assistant or digital assistant, is an application program that understands natural language voice commands and completes tasks for the user 5 | 6 | Hey There, I had manipulated Selenium WebDriver to make this assistant. 7 | I hope, It will be helpful for beginner. 8 | 9 | Break a Leg, 10 | 11 | Peace✌ 12 | 13 | NB: You have to generate your API for Weather Forecast(openweathermap.org) And News(newsapi.org) 14 | -------------------------------------------------------------------------------- /Wikipedia.py: -------------------------------------------------------------------------------- 1 | from selenium import webdriver 2 | 3 | 4 | class infowiki: 5 | def __init__(self): 6 | self.driver = webdriver.Chrome(executable_path='path/chromedriver.exe') 7 | 8 | def get_info(self, query): 9 | self.query = query 10 | self.driver.get(url='https://www.wikipedia.org/') 11 | search = self.driver.find_element_by_xpath('//*[@id="searchInput"]') 12 | search.click() 13 | search.send_keys(query) 14 | enter = self.driver.find_element_by_xpath('//*[@id="search-form"]/fieldset/button/i') 15 | enter.click() 16 | 17 | # assist = infowiki() 18 | # assist.get_info('Black hole') 19 | -------------------------------------------------------------------------------- /Email.py: -------------------------------------------------------------------------------- 1 | import smtplib 2 | import ssl 3 | 4 | from API import * 5 | 6 | port = 587 # For starttls 7 | smtp_server = "smtp.gmail.com" 8 | sender_email = "sender_email@gmail.com" 9 | receiver_email = "receiver_email@gmail.com" 10 | # password = input("Type your password and press enter:") 11 | message = """\ 12 | Subject: Greetings 13 | 14 | Hope that you are well. 15 | Regards 16 | Maruf Billah.""" 17 | 18 | 19 | def sendEmail(): 20 | context = ssl.create_default_context() 21 | with smtplib.SMTP(smtp_server, port) as server: 22 | server.ehlo() # Can be omitted 23 | server.starttls(context=context) 24 | server.ehlo() # Can be omitted 25 | server.login(sender_email, password) 26 | server.sendmail(sender_email, receiver_email, message) 27 | 28 | # sendEmail() 29 | -------------------------------------------------------------------------------- /Basic Assistant.py: -------------------------------------------------------------------------------- 1 | import datetime 2 | import sys 3 | import randfacts 4 | import pyttsx3 as p 5 | import speech_recognition as sr 6 | from Wikipedia import * 7 | from Youtube import * 8 | from News import * 9 | from Weather import * 10 | from Email import * 11 | 12 | engine = p.init('sapi5') 13 | rate = engine.getProperty('rate') 14 | engine.setProperty('rate', 170) 15 | voices = engine.getProperty('voices') 16 | engine.setProperty('voice', voices[1].id) 17 | 18 | 19 | def speak(sound): 20 | engine.say(sound) 21 | engine.runAndWait() 22 | 23 | 24 | def greetMe(): 25 | hour = (datetime.datetime.now().hour) 26 | if 0 <= hour <= 11: 27 | return 'Good Morning!' 28 | elif 12 <= hour < 18: 29 | return 'Good Afternoon!' 30 | else: 31 | return 'Good Evening!' 32 | 33 | 34 | today = datetime.datetime.now() 35 | speak(greetMe() + "sir, " + " I am your AI Assistant.") 36 | print(today.strftime('%d %B %Y ') + today.strftime('%I:%M %p')) 37 | speak('today is ' + today.strftime('%d') + " of " + today.strftime('%B %Y') + 38 | ', And it currently ' + today.strftime('%I:%M %p')) 39 | print(str(temperature())) 40 | print(str(description())) 41 | speak('Temperature in Bogura is ' + str(temperature()) + " degree Celsius" + ' and with' + str(description())) 42 | speak('How are you?') 43 | 44 | 45 | def pack(): 46 | r = sr.Recognizer() 47 | with sr.Microphone(device_index=1) as source: 48 | r.energy_threshold = 1000 49 | r.adjust_for_ambient_noise(source, 1.2) 50 | print('listening...') 51 | audio = r.listen(source) 52 | try: 53 | text = r.recognize_google(audio) 54 | except Exception: 55 | print('say that again please...') 56 | return 'None' 57 | 58 | if 'what' and 'about' and 'you' in text: 59 | speak('I am having a good day') 60 | speak('What can I do for you?') 61 | 62 | with sr.Microphone(device_index=1) as source: 63 | r.energy_threshold = 1000 64 | r.adjust_for_ambient_noise(source, 1.2) 65 | print('listening...') 66 | audio = r.listen(source) 67 | try: 68 | command = r.recognize_google(audio) 69 | except Exception: 70 | print('say that again please...') 71 | return 'None' 72 | 73 | if 'information' in command: 74 | speak('you need information to which topic?') 75 | with sr.Microphone(device_index=1) as source: 76 | r.energy_threshold = 1000 77 | r.adjust_for_ambient_noise(source, 1.2) 78 | print('listening...') 79 | audio = r.listen(source) 80 | try: 81 | info = r.recognize_google(audio) 82 | except Exception: 83 | print('say that again please...') 84 | return 'None' 85 | print(f'user said:{info}') 86 | speak(f'Searching {info} in wikipedia') 87 | assist = infowiki() 88 | assist.get_info(info) 89 | 90 | elif 'play' and 'video' in command: 91 | speak('you want me to play which video?') 92 | with sr.Microphone(device_index=1) as source: 93 | r.energy_threshold = 1000 94 | r.adjust_for_ambient_noise(source, 1.2) 95 | print('listening...') 96 | audio = r.listen(source) 97 | try: 98 | video = r.recognize_google(audio) 99 | except Exception: 100 | print('say that again please...') 101 | return 'None' 102 | speak(f'Playing {video} on youtube') 103 | assist = youtube() 104 | assist.play(video) 105 | 106 | elif 'news' in command: 107 | speak('definitely, Now I will read news for you.') 108 | arr = news() 109 | for i in range(len(arr)): 110 | print(arr[i]) 111 | speak(arr[i]) 112 | 113 | elif 'fact' in command: 114 | x = randfacts.getFact() 115 | print(f'Fact: {x}') 116 | speak('Did you know that, ' + x) 117 | 118 | elif 'send the email' in command: 119 | try: 120 | sendEmail() 121 | speak('Email sent successfully') 122 | except Exception as em: 123 | print(em) 124 | speak('Sorry , Something went wrong. I am not able to send this email. Please try again') 125 | return 'None' 126 | elif 'stop' in command: 127 | sys.exit() 128 | 129 | 130 | while True: 131 | pack() 132 | --------------------------------------------------------------------------------