├── .gitignore ├── LICENSE ├── README.md ├── environment.yml ├── main.py ├── play.py ├── read.py ├── requirements.txt ├── sendmail.py ├── weather.py └── whatsapp.py /.gitignore: -------------------------------------------------------------------------------- 1 | __pycache__/ 2 | *.py[cod] 3 | 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Rishabh Gupta 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Voice-Assistant 2 | 3 | This is a simple virtual assistant written in Python 3. 4 | 5 | [Watch the video](https://drive.google.com/file/d/1eDrGoe3ID1LTuLvyO1KbA7xZf6Pkf-oH/view?usp=sharing) 6 | 7 | ## Voice-Assistant Architecture 8 | Virtual assistants are built from the following components: 9 | * Voice Activity Detection (VAD) - this determines when the user starts and stops speaking. Voice-Assistant uses the python [SpeechRecognition](https://github.com/Uberi/speech_recognition) module for VAD. 10 | * Speech to Text (STT) - This converts the audio that was recorded between when the VAD recognized that the user started speaking and when the user ended speaking. Voice-Assistant uses the default STT provider for the python SpeechRecognition module, which is currently a free online service from Google called "Google Speech Recognition". The SpeechRecognition module can also use Pocketsphinx for offline recognition. 11 | * Text to Intent - This takes the recognized text from the STT engine and figures out what action you want the assistant to perform. Usually the full recognized text is passed to the action to search for keywords. This is the bulk of what the digital_assistant method in the main.py script does. 12 | * Action - this performs some action based on the intent. It usually responds with a text message. 13 | * Text to Speech (TTS) - this converts text, usually returned by an action, to speech which is then played by the computer as a response. 14 | 15 | ## Installation 16 | 17 | ### Windows 18 | Voice-Assistant runs well on Windows. For the easiest setup, you should probably download and install [Anaconda](https://www.anaconda.com/products/individual) and then use the conda command with the environment.yml file from the Anaconda prompt to create a virtual environment for yourself. 19 | 20 | ```dos 21 | (base) C:\Projects\Voice-Assistant>conda env create -f environment.yml 22 | ``` 23 | To run voice assistant, activate the virtual environment from the Anaconda prompt and use python to run main.py: 24 | ```dos 25 | (base) C:\Projects\Voice-Assistant>conda activate Voice-Assistant 26 | (Voice-Assistant) C:\Projects\Voice-Assistant>python main.py 27 | ``` 28 | 29 | ### Linux 30 | Voice-Assistant works well with Linux. It should run on a Raspberry Pi or other SBC or within Linux installed on a virtual machine like on VirtualBox. 31 | 32 | Most Linux distros already have Python 3 installed. 33 | 34 | You should always use Voice Assistant within a virtual environment, especially on Linux where system utilities are likely to be written in your system Python. Getting your system environment messed up when a required library gets changed is never fun. 35 | 36 | On Debian derivatives like Ubuntu, Mint, Raspbian, etc. you can install a virtual environment using VirtualEnvWrapper: 37 | 38 | ```bash 39 | ~/Voice-Assistant $ sudo apt install virtualenvwrapper 40 | ~/Voice-Assistant $ echo ". /usr/share/virtualenvwrapper/virtualenvwrapper.sh" >> ~/.bashrc 41 | ~/Voice-Assistant $ . /usr/share/virtualenvwrapper/virtualenvwrapper.sh 42 | ~/Voice-Assistant $ mkvirtualenv -p /usr/bin/python3 Voice-Assistant 43 | (Voice-Assistant) ~/Voice-Assistant $ 44 | ``` 45 | 46 | You will probably need to install eSpeak and PortAudio. On Debian derivatives, these can be installed with: 47 | 48 | ``` 49 | ~/Voice-Assistant $ sudo apt install portaudio19-dev libespeak-dev 50 | ``` 51 | then activate your virtual environment and use the requirements.txt file to load the required modules: 52 | ``` 53 | ~/Voice-Assistant $ workon Voice-Assistant 54 | (Voice-Assistant) ~/Voice-Assistant $ pip install -r requirements.txt 55 | ``` 56 | 57 | To run Voice-Assistant, you should activate the virtual environment, then use python to run the main.py script: 58 | 59 | ``` 60 | ~/Voice-Assistant $ workon Voice-Assistant 61 | (Voice-Assistant) ~/Voice-Assistant $ python main.py 62 | ``` 63 | -------------------------------------------------------------------------------- /environment.yml: -------------------------------------------------------------------------------- 1 | name: Voice-Assistant 2 | channels: 3 | - conda-forge 4 | - defaults 5 | dependencies: 6 | - alabaster=0.7.12=py_0 7 | - anaconda=2020.07=py38_0 8 | - anaconda-client=1.7.2=py38_0 9 | - anaconda-project=0.8.4=py_0 10 | - argh=0.26.2=py38_0 11 | - asn1crypto=1.3.0=py38_0 12 | - astroid=2.4.2=py38_0 13 | - astropy=4.0.1.post1=py38he774522_1 14 | - atomicwrites=1.4.0=py_0 15 | - attrs=19.3.0=py_0 16 | - autopep8=1.5.3=py_0 17 | - babel=2.8.0=py_0 18 | - backcall=0.2.0=py_0 19 | - backports=1.0=py_2 20 | - backports.shutil_get_terminal_size=1.0.0=py38_2 21 | - bcrypt=3.1.7=py38he774522_1 22 | - beautifulsoup4=4.9.1=py38_0 23 | - bitarray=1.4.0=py38he774522_0 24 | - bkcharts=0.2=py38_0 25 | - blas=1.0=mkl 26 | - bleach=3.1.5=py_0 27 | - blosc=1.19.0=h7bd577a_0 28 | - bokeh=2.1.1=py38_0 29 | - boto=2.49.0=py38_0 30 | - bottleneck=1.3.2=py38h2a96729_1 31 | - brotlipy=0.7.0=py38he774522_1000 32 | - bs4=4.9.1=0 33 | - bzip2=1.0.8=he774522_0 34 | - ca-certificates=2020.6.24=0 35 | - certifi=2020.6.20=py38_0 36 | - cffi=1.14.0=py38h7a1dbc1_0 37 | - chardet=3.0.4=py38_1003 38 | - click=7.1.2=py_0 39 | - cloudpickle=1.5.0=py_0 40 | - clyent=1.2.2=py38_1 41 | - colorama=0.4.3=py_0 42 | - comtypes=1.1.7=py38_1001 43 | - console_shortcut=0.1.1=4 44 | - contextlib2=0.6.0.post1=py_0 45 | - cryptography=2.9.2=py38h7a1dbc1_0 46 | - curl=7.71.1=h2a8f88b_1 47 | - cycler=0.10.0=py38_0 48 | - cython=0.29.21=py38ha925a31_0 49 | - cytoolz=0.10.1=py38he774522_0 50 | - dask=2.20.0=py_0 51 | - dask-core=2.20.0=py_0 52 | - decorator=4.4.2=py_0 53 | - defusedxml=0.6.0=py_0 54 | - diff-match-patch=20200713=py_0 55 | - distributed=2.20.0=py38_0 56 | - docutils=0.16=py38_1 57 | - entrypoints=0.3=py38_0 58 | - et_xmlfile=1.0.1=py_1001 59 | - fastcache=1.1.0=py38he774522_0 60 | - filelock=3.0.12=py_0 61 | - flake8=3.8.3=py_0 62 | - flask=1.1.2=py_0 63 | - freetype=2.10.2=hd328e21_0 64 | - fsspec=0.7.4=py_0 65 | - future=0.18.2=py38_1 66 | - get_terminal_size=1.0.0=h38e98db_0 67 | - gevent=20.6.2=py38he774522_0 68 | - glob2=0.7=py_0 69 | - gmpy2=2.0.8=py38h7edee0f_3 70 | - greenlet=0.4.16=py38he774522_0 71 | - h5py=2.10.0=py38h5e291fa_0 72 | - hdf5=1.10.4=h7ebc959_0 73 | - heapdict=1.0.1=py_0 74 | - html5lib=1.1=py_0 75 | - icc_rt=2019.0.0=h0cc432a_1 76 | - icu=58.2=ha925a31_3 77 | - idna=2.10=py_0 78 | - imageio=2.9.0=py_0 79 | - imagesize=1.2.0=py_0 80 | - importlib-metadata=1.7.0=py38_0 81 | - importlib_metadata=1.7.0=0 82 | - intel-openmp=2020.1=216 83 | - intervaltree=3.0.2=py_1 84 | - ipykernel=5.3.2=py38h5ca1d4c_0 85 | - ipython=7.16.1=py38h5ca1d4c_0 86 | - ipython_genutils=0.2.0=py38_0 87 | - ipywidgets=7.5.1=py_0 88 | - isort=4.3.21=py38_0 89 | - itsdangerous=1.1.0=py_0 90 | - jdcal=1.4.1=py_0 91 | - jedi=0.17.1=py38_0 92 | - jinja2=2.11.2=py_0 93 | - joblib=0.16.0=py_0 94 | - jpeg=9b=hb83a4c4_2 95 | - json5=0.9.5=py_0 96 | - jsonschema=3.2.0=py38_0 97 | - jupyter=1.0.0=py38_7 98 | - jupyter_client=6.1.6=py_0 99 | - jupyter_console=6.1.0=py_0 100 | - jupyter_core=4.6.3=py38_0 101 | - jupyterlab=2.1.5=py_0 102 | - jupyterlab_server=1.2.0=py_0 103 | - keyring=21.2.1=py38_0 104 | - kiwisolver=1.2.0=py38h74a9793_0 105 | - krb5=1.18.2=hc04afaa_0 106 | - lazy-object-proxy=1.4.3=py38he774522_0 107 | - libarchive=3.4.2=h5e25573_0 108 | - libcurl=7.71.1=h2a8f88b_1 109 | - libiconv=1.15=h1df5818_7 110 | - liblief=0.10.1=ha925a31_0 111 | - libllvm9=9.0.1=h21ff451_0 112 | - libpng=1.6.37=h2a8f88b_0 113 | - libsodium=1.0.18=h62dcd97_0 114 | - libspatialindex=1.9.3=h33f27b4_0 115 | - libssh2=1.9.0=h7a1dbc1_1 116 | - libtiff=4.1.0=h56a325e_1 117 | - libxml2=2.9.10=h464c3ec_1 118 | - libxslt=1.1.34=he774522_0 119 | - llvmlite=0.33.0=py38ha925a31_0 120 | - locket=0.2.0=py38_1 121 | - lxml=4.5.2=py38h1350720_0 122 | - lz4-c=1.9.2=h62dcd97_0 123 | - lzo=2.10=he774522_2 124 | - m2w64-gcc-libgfortran=5.3.0=6 125 | - m2w64-gcc-libs=5.3.0=7 126 | - m2w64-gcc-libs-core=5.3.0=7 127 | - m2w64-gmp=6.1.0=2 128 | - m2w64-libwinpthread-git=5.0.0.4634.697f757=2 129 | - markupsafe=1.1.1=py38he774522_0 130 | - matplotlib=3.2.2=0 131 | - matplotlib-base=3.2.2=py38h64f37c6_0 132 | - mccabe=0.6.1=py38_1 133 | - menuinst=1.4.16=py38he774522_1 134 | - mistune=0.8.4=py38he774522_1000 135 | - mkl=2020.1=216 136 | - mkl-service=2.3.0=py38hb782905_0 137 | - mkl_fft=1.1.0=py38h45dec08_0 138 | - mkl_random=1.1.1=py38h47e9c7a_0 139 | - mock=4.0.2=py_0 140 | - more-itertools=8.4.0=py_0 141 | - mpc=1.1.0=h7edee0f_1 142 | - mpfr=4.0.2=h62dcd97_1 143 | - mpir=3.0.0=hec2e145_1 144 | - mpmath=1.1.0=py38_0 145 | - msgpack-python=1.0.0=py38h74a9793_1 146 | - msys2-conda-epoch=20160418=1 147 | - multipledispatch=0.6.0=py38_0 148 | - nbconvert=5.6.1=py38_0 149 | - nbformat=5.0.7=py_0 150 | - networkx=2.4=py_1 151 | - nltk=3.5=py_0 152 | - nose=1.3.7=py38_2 153 | - notebook=6.0.3=py38_0 154 | - numba=0.50.1=py38h47e9c7a_0 155 | - numexpr=2.7.1=py38h25d0782_0 156 | - numpy=1.18.5=py38h6530119_0 157 | - numpy-base=1.18.5=py38hc3f5095_0 158 | - numpydoc=1.1.0=py_0 159 | - olefile=0.46=py_0 160 | - openpyxl=3.0.4=py_0 161 | - openssl=1.1.1g=he774522_0 162 | - packaging=20.4=py_0 163 | - pandas=1.0.5=py38h47e9c7a_0 164 | - pandoc=2.10=0 165 | - pandocfilters=1.4.2=py38_1 166 | - paramiko=2.7.1=py_0 167 | - parso=0.7.0=py_0 168 | - partd=1.1.0=py_0 169 | - path=13.1.0=py38_0 170 | - path.py=12.4.0=0 171 | - pathlib2=2.3.5=py38_0 172 | - pathtools=0.1.2=py_1 173 | - patsy=0.5.1=py38_0 174 | - pep8=1.7.1=py38_0 175 | - pexpect=4.8.0=py38_0 176 | - pickleshare=0.7.5=py38_1000 177 | - pillow=7.2.0=py38hcc1f983_0 178 | - pip=20.1.1=py38_1 179 | - pkginfo=1.5.0.1=py38_0 180 | - pluggy=0.13.1=py38_0 181 | - ply=3.11=py38_0 182 | - portaudio=19.6.0=he774522_4 183 | - powershell_shortcut=0.0.1=3 184 | - prometheus_client=0.8.0=py_0 185 | - prompt-toolkit=3.0.5=py_0 186 | - prompt_toolkit=3.0.5=0 187 | - psutil=5.7.0=py38he774522_0 188 | - py=1.9.0=py_0 189 | - py-lief=0.10.1=py38ha925a31_0 190 | - pyaudio=0.2.11=py38he774522_2 191 | - pyautogui=0.9.48=py38_0 192 | - pycodestyle=2.6.0=py_0 193 | - pycosat=0.6.3=py38he774522_0 194 | - pycparser=2.20=py_2 195 | - pycurl=7.43.0.5=py38h7a1dbc1_0 196 | - pydocstyle=5.0.2=py_0 197 | - pyflakes=2.2.0=py_0 198 | - pygments=2.6.1=py_0 199 | - pylint=2.5.3=py38_0 200 | - pymsgbox=1.0.7=py_0 201 | - pynacl=1.4.0=py38h62dcd97_1 202 | - pyodbc=4.0.30=py38ha925a31_0 203 | - pyopenssl=19.1.0=py_1 204 | - pyparsing=2.4.7=py_0 205 | - pyqt=5.9.2=py38ha925a31_4 206 | - pyreadline=2.1=py38_1 207 | - pyrsistent=0.16.0=py38he774522_0 208 | - pyscreeze=0.1.26=py_0 209 | - pysocks=1.7.1=py38_0 210 | - pytables=3.6.1=py38ha5be198_0 211 | - pytest=5.4.3=py38_0 212 | - python=3.8.3=he1778fa_2 213 | - python-dateutil=2.8.1=py_0 214 | - python-jsonrpc-server=0.3.4=py_1 215 | - python-language-server=0.34.1=py38_0 216 | - python-libarchive-c=2.9=py_0 217 | - python_abi=3.8=1_cp38 218 | - pytz=2020.1=py_0 219 | - pywavelets=1.1.1=py38he774522_0 220 | - pywin32=227=py38he774522_1 221 | - pywin32-ctypes=0.2.0=py38_1000 222 | - pywinpty=0.5.7=py38_0 223 | - pyyaml=5.3.1=py38he774522_1 224 | - pyzmq=19.0.1=py38ha925a31_1 225 | - qdarkstyle=2.8.1=py_0 226 | - qt=5.9.7=vc14h73c81de_0 227 | - qtawesome=0.7.2=py_0 228 | - qtconsole=4.7.5=py_0 229 | - qtpy=1.9.0=py_0 230 | - regex=2020.6.8=py38he774522_0 231 | - requests=2.24.0=py_0 232 | - rope=0.17.0=py_0 233 | - rtree=0.9.4=py38h21ff451_1 234 | - ruamel_yaml=0.15.87=py38he774522_1 235 | - scikit-image=0.16.2=py38h47e9c7a_0 236 | - scikit-learn=0.23.1=py38h25d0782_0 237 | - scipy=1.5.0=py38h9439919_0 238 | - seaborn=0.10.1=py_0 239 | - selenium=3.141.0=py38h9de7a3e_1001 240 | - send2trash=1.5.0=py38_0 241 | - setuptools=49.2.0=py38_0 242 | - simplegeneric=0.8.1=py38_2 243 | - singledispatch=3.4.0.3=py38_0 244 | - sip=4.19.13=py38ha925a31_0 245 | - six=1.15.0=py_0 246 | - snappy=1.1.8=h33f27b4_0 247 | - snowballstemmer=2.0.0=py_0 248 | - sortedcollections=1.2.1=py_0 249 | - sortedcontainers=2.2.2=py_0 250 | - soupsieve=2.0.1=py_0 251 | - speechrecognition=3.7.1=py38h32f6830_1 252 | - sphinx=3.1.2=py_0 253 | - sphinxcontrib=1.0=py38_1 254 | - sphinxcontrib-applehelp=1.0.2=py_0 255 | - sphinxcontrib-devhelp=1.0.2=py_0 256 | - sphinxcontrib-htmlhelp=1.0.3=py_0 257 | - sphinxcontrib-jsmath=1.0.1=py_0 258 | - sphinxcontrib-qthelp=1.0.3=py_0 259 | - sphinxcontrib-serializinghtml=1.1.4=py_0 260 | - sphinxcontrib-websupport=1.2.3=py_0 261 | - spyder=4.1.4=py38_0 262 | - spyder-kernels=1.9.2=py38_0 263 | - sqlalchemy=1.3.18=py38he774522_0 264 | - sqlite=3.32.3=h2a8f88b_0 265 | - statsmodels=0.11.1=py38he774522_0 266 | - sympy=1.6.1=py38_0 267 | - tbb=2020.0=h74a9793_0 268 | - tblib=1.6.0=py_0 269 | - terminado=0.8.3=py38_0 270 | - testpath=0.4.4=py_0 271 | - threadpoolctl=2.1.0=pyh5ca1d4c_0 272 | - tk=8.6.10=he774522_0 273 | - toml=0.10.1=py_0 274 | - toolz=0.10.0=py_0 275 | - tornado=6.0.4=py38he774522_1 276 | - tqdm=4.47.0=py_0 277 | - traitlets=4.3.3=py38_0 278 | - typing_extensions=3.7.4.2=py_0 279 | - ujson=1.35=py38he774522_0 280 | - unicodecsv=0.14.1=py38_0 281 | - urllib3=1.25.9=py_0 282 | - vc=14.1=h0510ff6_4 283 | - vs2015_runtime=14.16.27012=hf0eaf9b_3 284 | - watchdog=0.10.3=py38_0 285 | - wcwidth=0.2.5=py_0 286 | - webencodings=0.5.1=py38_1 287 | - werkzeug=1.0.1=py_0 288 | - wheel=0.34.2=py38_0 289 | - widgetsnbextension=3.5.1=py38_0 290 | - win_inet_pton=1.1.0=py38_0 291 | - win_unicode_console=0.5=py38_0 292 | - wincertstore=0.2=py38_0 293 | - winpty=0.4.3=4 294 | - wrapt=1.11.2=py38he774522_0 295 | - xlrd=1.2.0=py_0 296 | - xlsxwriter=1.2.9=py_0 297 | - xlwings=0.19.5=py38_0 298 | - xlwt=1.3.0=py38_0 299 | - xz=5.2.5=h62dcd97_0 300 | - yaml=0.2.5=he774522_0 301 | - yapf=0.30.0=py_0 302 | - zeromq=4.3.2=ha925a31_2 303 | - zict=2.0.0=py_0 304 | - zipp=3.1.0=py_0 305 | - zlib=1.2.11=h62dcd97_4 306 | - zope=1.0=py38_1 307 | - zope.event=4.4=py38_0 308 | - zope.interface=4.7.1=py38he774522_0 309 | - zstd=1.4.5=ha9fde0e_0 310 | - pip: 311 | - pyttsx3==2.90 312 | - pytweening==1.0.3 313 | prefix: C:\Users\achantrill\Anaconda3\envs\Virtual-Assistant 314 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | import speech_recognition as sr 2 | from selenium import webdriver 3 | import pyttsx3 4 | from time import ctime 5 | import time 6 | import webbrowser as wb 7 | import bs4 8 | import requests 9 | 10 | # CUSTOM MODULES 11 | import whatsapp 12 | import weather 13 | import play 14 | import read 15 | import sendmail 16 | 17 | 18 | def respond(AudioString): 19 | pyttsx3.speak(AudioString) 20 | 21 | 22 | def listen(): 23 | r = sr.Recognizer() 24 | with sr.Microphone() as source: 25 | print("I am listening...") 26 | audio = r.listen(source) 27 | cmd = "" 28 | try: 29 | cmd = r.recognize_google(audio) 30 | return cmd 31 | except sr.UnknownValueError: 32 | respond("Google Speech Recognition did not understand audio") 33 | except sr.RequestError as e: 34 | respond("Request Failed; {0}".format(e)) 35 | return cmd 36 | 37 | 38 | def digital_assistant(data): 39 | global sub 40 | if "how are you" in data: 41 | pyttsx3.speak("I am well") 42 | 43 | if "what time is it" in data: 44 | pyttsx3.speak(ctime()) 45 | 46 | if "stop listening" in data or "stop" in data or "quit" in data: 47 | lis = False 48 | print('Listening stopped') 49 | return lis 50 | 51 | if ("WhatsApp" or "whatsapp" or "WHATSAPP") in data: 52 | whatsapp.askinfo() 53 | # whatsapp.whatsapp_send(user, message) 54 | 55 | if "what can you do" in data: 56 | respond("can handle pretty much all your stuff, sir! however i am still learning so i'll be able to perform " 57 | "more task in future") 58 | 59 | if "where is" in data or "navigate to" in data: 60 | l = data.split(" ") 61 | loc = " ".join(l[2:]) 62 | location_url = f"https://www.google.com/maps/place/{str(loc)}" 63 | respond("Hold on Rishabh, I will show you where " + loc + " is.") 64 | browser = webdriver.Chrome() 65 | browser.get(location_url) 66 | time.sleep(1) 67 | search = browser.find_element_by_xpath("/html/body/jsl/div[3]/div[9]/div[3]/div[1]/div[1]/div[1]/div[2]/div[" 68 | "1]/button") 69 | search.click() 70 | time.sleep(3) 71 | if ("weather" or "climate") in data: 72 | weather.info(data) 73 | 74 | if "want to watch" in data or "stream" in data: # i want to watch tanmay bhat on youtube 75 | l = data.split(" ") 76 | iofp = l.index("on") 77 | if "stream" in data: 78 | video = "+".join(l[2:iofp]) 79 | else: 80 | video = "+".join(l[4:iofp]) 81 | platform = " ".join(l[iofp + 1:]) 82 | print(platform) 83 | play.movies(video, platform) 84 | 85 | if "play" in data: 86 | l = data.split(" ") 87 | song = " ".join(l[1:]) 88 | play.music(song) 89 | 90 | if "read" in data or "search" in data or "explain" in data or "what is" in data or "details" in data or "what are" in data: 91 | l = data.split(" ") 92 | # i = l.index("about") 93 | topic = l[-1] 94 | read.wikipedia(topic) 95 | 96 | if "email" in data: 97 | print(data) 98 | l = data.split(" ") 99 | respond("please enter the email address of the recipient") 100 | to = input() 101 | if "regarding" in data: 102 | r = l.index('regarding') 103 | sub = l[r + 1] 104 | else: 105 | respond("please tell me the subject regarding e-mail") 106 | sub = listen() 107 | respond("kindly tell me the body of e-mail") 108 | body = listen() 109 | 110 | sendmail.send(to, sub, body) 111 | 112 | print(data) 113 | 114 | lis: bool = True 115 | return lis 116 | 117 | 118 | if __name__ == "__main__": 119 | pyttsx3.speak("Hello Rishabh. what can i do for you?") 120 | # time.sleep(1) 121 | listening = True 122 | while listening: 123 | task = listen() 124 | listening = digital_assistant(task) -------------------------------------------------------------------------------- /play.py: -------------------------------------------------------------------------------- 1 | import main 2 | import webbrowser as wb 3 | import time 4 | import pyautogui 5 | 6 | 7 | def movies(video, platform): 8 | if ("Amazon" or "Prime") in platform: 9 | wb.open("https://www.primevideo.com/search/ref=atv_nb_sr?phrase=" + video) 10 | time.sleep(2) 11 | pyautogui.click(274, 423) 12 | elif "youtube" in platform.lower(): 13 | wb.open('https://www.youtube.com/results?search_query=' + video) 14 | time.sleep(5) 15 | 16 | 17 | def music(song): 18 | wb.open('https://music.youtube.com/search?q=' + song) 19 | time.sleep(2.5) 20 | pyautogui.click(560, 324) 21 | time.sleep(10) 22 | -------------------------------------------------------------------------------- /read.py: -------------------------------------------------------------------------------- 1 | import webbrowser 2 | import bs4 3 | import requests 4 | import pyttsx3 5 | import time 6 | 7 | 8 | def wikipedia(topic): 9 | global elem 10 | res = requests.get('https://en.wikipedia.org/wiki/' + topic) 11 | soup = bs4.BeautifulSoup(res.text, 'html.parser') 12 | time.sleep(2) 13 | try: 14 | elem = soup.select('#mw-content-text > div.mw-parser-output') 15 | except IndexError: 16 | pyttsx3.speak("sorry couldn't find that! please try again or try searching with different keywords") 17 | file = open(f'C:\\Users\\Asus\\Desktop\\{topic}.txt', 'w+', errors='ignore') 18 | content = elem[0].text 19 | file.write(content) 20 | file.close() 21 | pyttsx3.speak(f'file have been saved on your desktop. you may read about {topic} any time through that file.') 22 | time.sleep(8) 23 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | bs4==0.0.1 2 | PyAudio==0.2.11 3 | PyAutoGUI==0.9.50 4 | pyttsx3==2.90 5 | requests==2.24.0 6 | selenium==3.141.0 7 | SpeechRecognition==3.8.1 -------------------------------------------------------------------------------- /sendmail.py: -------------------------------------------------------------------------------- 1 | import smtplib 2 | import pyttsx3 3 | import main 4 | 5 | 6 | def send(to, sub, body): 7 | conn = smtplib.SMTP('smtp.gmail.com', 587) 8 | 9 | conn.ehlo() 10 | 11 | conn.starttls() 12 | 13 | conn.login('YOUR_EMAIL_ADDRESS', 'PASSWORD') 14 | 15 | 16 | 17 | conn.sendmail('YOUR_EMAIL_ADDRESS', to, 'Subject : ' + sub + '\n\n' + body) 18 | 19 | conn.quit() 20 | 21 | pyttsx3.speak('mail sent successfully') 22 | -------------------------------------------------------------------------------- /weather.py: -------------------------------------------------------------------------------- 1 | import main 2 | import requests 3 | import json 4 | 5 | 6 | def info(data): 7 | api_key = "a6b20a5000a5782be4dab5e6e39bbbf7" 8 | weather_url = "http://api.openweathermap.org/data/2.5/weather?" 9 | data = data.split(" ") 10 | location = str(data[-1]) 11 | url = weather_url + "appid=" + api_key + "&q=" + location 12 | js = requests.get(url).json() 13 | if js["cod"] != "404": 14 | weather = js["main"] 15 | temp = weather["temp"] 16 | hum = weather["humidity"] 17 | desc = js["weather"][0]["description"] 18 | resp_string = "in " + str(location) + " temperature in Kelvin is " + str(temp) + " The humidity is " + str(hum) + " and The weather description is "+ str(desc) 19 | main.respond(resp_string) 20 | else: 21 | main.respond("City Not Found") -------------------------------------------------------------------------------- /whatsapp.py: -------------------------------------------------------------------------------- 1 | from selenium import webdriver 2 | import time 3 | import pyttsx3 4 | 5 | # CUSTOM MODULES 6 | import main 7 | 8 | 9 | def whatsapp_send(name, msg): 10 | driver = webdriver.Chrome() 11 | driver.get('https://web.whatsapp.com') 12 | time.sleep(5) 13 | # name = input("whom do you want to send message") 14 | user = driver.find_element_by_xpath('//span[@title= "{}"]'.format(name)) 15 | time.sleep(3) 16 | user.click() 17 | time.sleep(1) 18 | msg_box = driver.find_element_by_xpath('//*[@id="main"]/footer/div[1]/div[2]') 19 | msg_box.send_keys(msg) 20 | msg_send = driver.find_element_by_xpath('//*[@id="main"]/footer/div[1]/div[3]/button') 21 | msg_send.click() 22 | 23 | 24 | def askinfo(): 25 | main.respond("whom do you want to send message?") 26 | user = main.listen() 27 | main.respond(f"please tell me the message to send to {user}") 28 | message = main.listen() 29 | main.respond("scan QR code in the next screen to continue login to whatsapp") 30 | whatsapp_send(user, message) 31 | main.respond("message send as you said, sir!") 32 | --------------------------------------------------------------------------------