Skip to content

Commit

Permalink
Merge pull request #34 from Curiouspaul1/updates
Browse files Browse the repository at this point in the history
Updates as regards application structure as specified in the issue #33
  • Loading branch information
GauravSingh9356 authored Oct 12, 2021
2 parents 1d11eb8 + 2114ceb commit 5e81ccd
Show file tree
Hide file tree
Showing 6 changed files with 178 additions and 368 deletions.
Binary file added PyAudio-0.2.11-cp38-cp38-win_amd64.whl
Binary file not shown.
15 changes: 5 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,12 @@
<h2>Required Packages</h2>

```
pip3 install SpeechRecognition
pip3 install jsonlib
pip3 install pyttsx3
pip3 install PyAudio
pip3 install geocoder
pip3 install loc
pip3 install wikipedia
pip install psutil
pip install pyjokes
pip install -r requirements.txt
```

> _ To install PyAudio on windows head over to https://www.lfd.uci.edu/~gohlke/pythonlibs/#pyaudio and download the .whl for your machine and run the installation as shown below, then install the remaining dependencies from the requirements.txt file. You may remove pyAduio from the requirements file if it interrupts your installation (its there for unix users)
```bash
pip install PyAudio‑0.2.11‑cp<version>‑cp<version>m‑win_amd<architecture>.whl
```

### On Ubuntu based Linux distribution you need to install the following packages, so that the code works:
Expand Down
94 changes: 94 additions & 0 deletions helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import pyttsx3
import pyautogui
import psutil
import pyjokes
import speech_recognition as sr
import json
import requests
import geocoder
from difflib import get_close_matches


engine = pyttsx3.init()
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[0].id)
g = geocoder.ip('me')
data = json.load(open('data.json'))

def speak(audio) -> None:
engine.say(audio)
engine.runAndWait()

def screenshot() -> None:
img = pyautogui.screenshot()
img.save('path of folder you want to save/screenshot.png')

def cpu() -> None:
usage = str(psutil.cpu_percent())
speak("CPU is at"+usage)

battery = psutil.sensors_battery()
speak("battery is at")
speak(battery.percent)

def joke() -> None:
for i in range(5):
speak(pyjokes.get_jokes()[i])

def takeCommand() -> str:
r = sr.Recognizer()
with sr.Microphone() as source:
print('Listening...')
r.pause_threshold = 1
r.energy_threshold = 494
r.adjust_for_ambient_noise(source, duration=1.5)
audio = r.listen(source)

try:
print('Recognizing..')
query = r.recognize_google(audio, language='en-in')
print(f'User said: {query}\n')

except Exception as e:
# print(e)

print('Say that again please...')
return 'None'
return query

def weather():
api_url = "https://fcc-weather-api.glitch.me/api/current?lat=" + \
str(g.latlng[0]) + "&lon=" + str(g.latlng[1])

data = requests.get(api_url)
data_json = data.json()
if data_json['cod'] == 200:
main = data_json['main']
wind = data_json['wind']
weather_desc = data_json['weather'][0]
speak(str(data_json['coord']['lat']) + 'latitude' + str(data_json['coord']['lon']) + 'longitude')
speak('Current location is ' + data_json['name'] + data_json['sys']['country'] + 'dia')
speak('weather type ' + weather_desc['main'])
speak('Wind speed is ' + str(wind['speed']) + ' metre per second')
speak('Temperature: ' + str(main['temp']) + 'degree celcius')
speak('Humidity is ' + str(main['humidity']))


def translate(word):
word = word.lower()
if word in data:
speak(data[word])
elif len(get_close_matches(word, data.keys())) > 0:
x = get_close_matches(word, data.keys())[0]
speak('Did you mean ' + x +
' instead, respond with Yes or No.')
ans = takeCommand().lower()
if 'yes' in ans:
speak(data[x])
elif 'no' in ans:
speak("Word doesn't exist. Please make sure you spelled it correctly.")
else:
speak("We didn't understand your entry.")

else:
speak("Word doesn't exist. Please double check it.")
168 changes: 51 additions & 117 deletions jarvis.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,10 @@
import os
import sys
import smtplib
import psutil
import pyjokes
import pyautogui
from news import speak_news, getNewsUrl
from diction import translate
from loc import weather
from helpers import *
from youtube import youtube
import psutil
import pyjokes
from sys import platform
import os
import getpass
Expand All @@ -25,123 +20,53 @@

# print(voices[0].id)


def speak(audio):
engine.say(audio)
engine.runAndWait()


def screenshot():
img = pyautogui.screenshot()
img.save('path of folder you want to save/screenshot.png')


def cpu():
usage = str(psutil.cpu_percent())
speak("CPU is at"+usage)

battery = psutil.sensors_battery()
speak("battery is at")
speak(battery.percent)


def joke():
for i in range(5):
speak(pyjokes.get_jokes()[i])


def takeCommand():

r = sr.Recognizer()
with sr.Microphone() as source:
print('Listening...')
r.pause_threshold = 1
r.energy_threshold = 494
r.adjust_for_ambient_noise(source, duration=1.5)
audio = r.listen(source)

try:
print('Recognizing..')
query = r.recognize_google(audio, language='en-in')
print(f'User said: {query}\n')

except Exception as e:
# print(e)

print('Say that again please...')
return 'None'
return query


def wishMe():
hour = int(datetime.datetime.now().hour)
if hour >= 0 and hour < 12:
speak("Good Morning SIR")
elif hour >= 12 and hour < 18:
speak("Good Afternoon SIR")

else:
speak('Good Evening SIR')

weather()
speak('I am JARVIS. Please tell me how can I help you SIR?')


def sendEmail(to, content):
server = smtplib.SMTP('smtp.gmail.com', 587)
server.ehlo()
server.starttls()
server.login('email', 'password')
server.sendmail('email', to, content)
server.close()


def cpu():
usage = str(psutil.cpu_percent())
speak("CPU is at"+usage)

battery = psutil.sensors_battery()
speak("battery is at")
speak(battery.percent)


def joke():
for i in range(5):
speak(pyjokes.get_jokes()[i])


def screenshot():
img = pyautogui.screenshot()
img.save('path of folder you want to save/screenshot.png')


if __name__ == '__main__':

if platform == "linux" or platform == "linux2":
chrome_path = '/usr/bin/google-chrome'

elif platform == "darwin":
chrome_path = 'open -a /Applications/Google\ Chrome.app'

elif platform == "win32":
chrome_path = 'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe'
else:
print('Unsupported OS')
exit(1)

webbrowser.register(
'chrome', None, webbrowser.BackgroundBrowser(chrome_path))
wishMe()
while True:
query = takeCommand().lower()
class Jarvis:
def __init__(self) -> None:
if platform == "linux" or platform == "linux2":
self.chrome_path = '/usr/bin/google-chrome'

elif platform == "darwin":
self.chrome_path = 'open -a /Applications/Google\ Chrome.app'

elif platform == "win32":
self.chrome_path = 'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe'
else:
print('Unsupported OS')
exit(1)
webbrowser.register(
'chrome', None, webbrowser.BackgroundBrowser(self.chrome_path)
)

def wishMe(self) -> None:
hour = int(datetime.datetime.now().hour)
if hour >= 0 and hour < 12:
speak("Good Morning SIR")
elif hour >= 12 and hour < 18:
speak("Good Afternoon SIR")

else:
speak('Good Evening SIR')

weather()
speak('I am JARVIS. Please tell me how can I help you SIR?')

def sendEmail(self, to, content) -> None:
server = smtplib.SMTP('smtp.gmail.com', 587)
server.ehlo()
server.starttls()
server.login('email', 'password')
server.sendmail('email', to, content)
server.close()

def execute_query(self, query):
# TODO: make this more concise
if 'wikipedia' in query:
speak('Searching Wikipedia....')
query = query.replace('wikipedia', '')
results = wikipedia.summary(query, sentences=2)
speak('According to Wikipedia')
print(results)
speak(results)

elif 'youtube downloader' in query:
exec(open('youtube_downloader.py').read())

Expand Down Expand Up @@ -290,8 +215,17 @@ def screenshot():
speak('What should I say?')
content = takeCommand()
to = 'email'
sendEmail(to, content)
self.sendEmail(to, content)
speak('Email has been sent!')

except Exception as e:
speak('Sorry sir, Not able to send email at the moment')



if __name__ == '__main__':
bot_ = Jarvis()
bot_.wishMe()
while True:
query = takeCommand().lower()
bot_.execute_query(query)
37 changes: 0 additions & 37 deletions loc.py

This file was deleted.

Loading

0 comments on commit 5e81ccd

Please sign in to comment.