├── .gitignore ├── README.md ├── Virtual Assistant Doc File.docx ├── Virtual Assistant PDF File.pdf ├── Virtual Assistant Presentation.pptx └── Virtual_Assistant.py /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | *.egg-info/ 24 | .installed.cfg 25 | *.egg 26 | MANIFEST 27 | 28 | # PyInstaller 29 | # Usually these files are written by a python script from a template 30 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 31 | *.manifest 32 | *.spec 33 | 34 | # Installer logs 35 | pip-log.txt 36 | pip-delete-this-directory.txt 37 | 38 | # Unit test / coverage reports 39 | htmlcov/ 40 | .tox/ 41 | .coverage 42 | .coverage.* 43 | .cache 44 | nosetests.xml 45 | coverage.xml 46 | *.cover 47 | .hypothesis/ 48 | .pytest_cache/ 49 | 50 | # Translations 51 | *.mo 52 | *.pot 53 | 54 | # Django stuff: 55 | *.log 56 | local_settings.py 57 | db.sqlite3 58 | 59 | # Flask stuff: 60 | instance/ 61 | .webassets-cache 62 | 63 | # Scrapy stuff: 64 | .scrapy 65 | 66 | # Sphinx documentation 67 | docs/_build/ 68 | 69 | # PyBuilder 70 | target/ 71 | 72 | # Jupyter Notebook 73 | .ipynb_checkpoints 74 | 75 | # pyenv 76 | .python-version 77 | 78 | # celery beat schedule file 79 | celerybeat-schedule 80 | 81 | # SageMath parsed files 82 | *.sage.py 83 | 84 | # Environments 85 | .env 86 | .venv 87 | env/ 88 | venv/ 89 | ENV/ 90 | env.bak/ 91 | venv.bak/ 92 | 93 | # Spyder project settings 94 | .spyderproject 95 | .spyproject 96 | 97 | # Rope project settings 98 | .ropeproject 99 | 100 | # mkdocs documentation 101 | /site 102 | 103 | # mypy 104 | .mypy_cache/ 105 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Virtual-Assistant-Using-Google-API-In-Python 2 | An attempt to make a very simple, Personal Assistant that understands speech as well as text input and is capable of performing tasks other than conversing. It performs basic functionalities with required internet connection. It can perform tasks as follows: 3 | 4 | 1. It can open any site for you where you can find anything you want to find. 5 | 2. It can tell time, name, reboot system and other basic operations with operating system. 6 | 3. It can open the place in the maps which you want to explore. 7 | 4. It can tell the Hindi meaning of any English word. 8 | 5. It can tell the weather of the place you queried. 9 | 6. It can Play any song of your choice. 10 | 7. It can search games you want to play. 11 | 8. It can scrap text from Wikipedia and read the text for you. 12 | 9. It can tell you a joke. 13 | 10. It can search any query on google search engine. 14 | -------------------------------------------------------------------------------- /Virtual Assistant Doc File.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/black-shadows/Virtual-Assistant-Using-Google-API-In-Python/bbeb4017f97c5b6f06860923c36d61dd152a5661/Virtual Assistant Doc File.docx -------------------------------------------------------------------------------- /Virtual Assistant PDF File.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/black-shadows/Virtual-Assistant-Using-Google-API-In-Python/bbeb4017f97c5b6f06860923c36d61dd152a5661/Virtual Assistant PDF File.pdf -------------------------------------------------------------------------------- /Virtual Assistant Presentation.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/black-shadows/Virtual-Assistant-Using-Google-API-In-Python/bbeb4017f97c5b6f06860923c36d61dd152a5661/Virtual Assistant Presentation.pptx -------------------------------------------------------------------------------- /Virtual_Assistant.py: -------------------------------------------------------------------------------- 1 | from time import ctime 2 | from gtts import gTTS 3 | import speech_recognition as sr 4 | import re 5 | import wikipedia 6 | import webbrowser 7 | import requests 8 | import os 9 | from pygame import mixer 10 | import sys 11 | from argparse import ArgumentParser 12 | from bs4 import BeautifulSoup 13 | import urllib.request 14 | from xml.dom import minidom 15 | 16 | i = 0 17 | 18 | 19 | def speak(audio_string): 20 | global i 21 | i = i + 1 22 | print(audio_string) 23 | tts = gTTS(text=audio_string, lang='en', slow=False) 24 | tts.save("audio" + str(i) + ".mp3") 25 | mixer.init() 26 | mixer.music.load("audio" + str(i) + ".mp3") 27 | mixer.music.play() 28 | 29 | 30 | def my_command(): 31 | """listens for commands""" 32 | 33 | r = sr.Recognizer() 34 | 35 | with sr.Microphone(device_index=0, chunk_size=2048, sample_rate=48000) as source: 36 | print('Listening...') 37 | r.pause_threshold = 1 38 | r.adjust_for_ambient_noise(source, duration=1) 39 | audio = r.listen(source) 40 | 41 | try: 42 | command = r.recognize_google(audio).lower() 43 | print('You said: ' + command + '\n') 44 | 45 | # loop back to continue to listen for commands if unrecognizable speech is received 46 | except sr.UnknownValueError: 47 | print('Your last command couldn\'t be heard') 48 | command = my_command() 49 | 50 | return command 51 | 52 | 53 | def assistant(command): 54 | """if statements for executing commands""" 55 | 56 | if 'open reddit' in command: 57 | reg_ex = re.search('open reddit (.*)', command) 58 | url = 'https://www.reddit.com/' 59 | if reg_ex: 60 | subreddit = reg_ex.group(1) 61 | url = url + 'r/' + subreddit 62 | webbrowser.open(url) 63 | print('Done!') 64 | 65 | elif 'open' in command: 66 | reg_ex = re.search('open (.+)', command) 67 | if reg_ex: 68 | domain = reg_ex.group(1) 69 | url = 'https://www.' + domain + '.com' 70 | webbrowser.open(url) 71 | print('Done!') 72 | else: 73 | pass 74 | 75 | elif 'what are you doing' in command: 76 | speak('Just doing my thing') 77 | 78 | elif 'search' in command: 79 | reg_ex = re.search('search (.+)', command) 80 | if reg_ex: 81 | domain = reg_ex.group(1) 82 | url = 'https://www.google.com/maps/place/' + domain 83 | webbrowser.open(url) 84 | print('Done!') 85 | else: 86 | pass 87 | 88 | elif 'find' in command: 89 | reg_ex = re.search('find (.+)', command) 90 | if reg_ex: 91 | domain = reg_ex.group(1) 92 | url = 'https://www.google.co.in/search?q=' + domain 93 | webbrowser.open(url) 94 | print('Done!') 95 | else: 96 | pass 97 | 98 | elif 'tell weather at' in command: 99 | reg_ex = re.search('tell weather at(.+)', command) 100 | if reg_ex: 101 | domain = reg_ex.group(1) 102 | url = 'http://www.intellicast.com/Local/Default.aspx?query=' + domain 103 | webbrowser.open(url) 104 | print('Done!') 105 | else: 106 | pass 107 | 108 | elif 'what is your name' in command: 109 | speak('Melissa') 110 | 111 | elif 'meaning' in command: 112 | reg_ex = re.search('meaning (.+)', command) 113 | if reg_ex: 114 | domain = reg_ex.group(1) 115 | url = 'https://translate.google.com/#en/hi/' + domain 116 | webbrowser.open(url) 117 | print('Done!') 118 | else: 119 | pass 120 | 121 | elif 'reboot system' in command: 122 | os.system('reboot') 123 | 124 | elif 'game' in command: 125 | reg_ex = re.search('game (.+)', command) 126 | if reg_ex: 127 | domain = reg_ex.group(1) 128 | url = 'https://www.miniclip.com/games/search/en/?query=' + domain 129 | webbrowser.open(url) 130 | print('Done!') 131 | else: 132 | pass 133 | 134 | elif 'who are you' in command: 135 | speak('your personal assistant') 136 | 137 | elif 'play' in command: 138 | reg_ex = re.search('play (.+)', command) 139 | if reg_ex: 140 | domain = reg_ex.group(1) 141 | url = 'https://gaana.com/search/' + domain 142 | webbrowser.open(url) 143 | print('Done!') 144 | else: 145 | pass 146 | 147 | 148 | elif 'read' in command: 149 | reg_ex = re.search('read (.+)', command) 150 | if reg_ex: 151 | domain = reg_ex.group(1) 152 | url = 'https://en.wikipedia.org/wiki/' + domain 153 | source = requests.get(url).text 154 | soup = BeautifulSoup(source, 'lxml') 155 | summary = soup.find('div', class_ = 'mw-body').p.text 156 | webbrowser.open(url) 157 | speak(summary) 158 | 159 | 160 | elif 'joke' in command: 161 | res = requests.get( 162 | 'https://icanhazdadjoke.com/', 163 | headers={"Accept": "application/json"} 164 | ) 165 | if res.status_code == requests.codes.ok: 166 | speak(str(res.json()['joke'])) 167 | else: 168 | speak('oops!I ran out of jokes') 169 | 170 | elif "how are you" in command: 171 | speak("I am fine") 172 | 173 | elif "time" in command: 174 | speak(ctime()) 175 | else: 176 | speak("i don't know") 177 | 178 | 179 | speak('I am ready for your command') 180 | 181 | # loop to continue executing multiple commands 182 | while True: 183 | assistant(my_command()) 184 | --------------------------------------------------------------------------------