-
Notifications
You must be signed in to change notification settings - Fork 0
/
location.py
23 lines (19 loc) · 1.04 KB
/
location.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import pyttsx3
import requests
engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
engine.setProperty('voices',voices[0].id)
engine.setProperty("rate", 197)
def speak (audio): #Function that will convert text to speech
engine.say(audio)
print("Zion : ",audio)
engine.runAndWait()
def mylocation():
speak("wait sir, let me check")
try:
ip = requests.get('https://api.ipify.org').content.decode('utf8') #requesting my ip address from the ip-api site and decoding it to utf8 format
get_response = requests.get("http://ip-api.com/json/"+ip).json() #requesting my location info in byte string format from ip-api server and converting it into str dict type using json() method
speak(f"Sir, we are currently in {get_response['city']} of {get_response['regionName']} having postal code {get_response['zip']}")
except Exception as e:
speak("Sir due to network issue I am not able to request data from server")
speak("Please try again sometime later")