forked from GauravSingh9356/J.A.R.V.I.S
-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.py
94 lines (78 loc) · 2.71 KB
/
helpers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
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.")