-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathadaptive_tts.py
More file actions
62 lines (47 loc) · 1.15 KB
/
adaptive_tts.py
File metadata and controls
62 lines (47 loc) · 1.15 KB
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
from polly import Polly
import sys
import geocoder
from geopy.geocoders import Nominatim
import subprocess
import socket
def is_connected():
try:
socket.create_connection(("1.1.1.1", 53))
return True
except OSError:
pass
return False
g = geocoder.ip('me')
geolocator = Nominatim(user_agent="geoapiExercises")
Latitude = str(g.latlng[0])
Longitude = str(g.latlng[1])
location = geolocator.reverse(Latitude+","+Longitude)
address = location.raw['address']
country = address.get('country', '')
voice = None
if country == 'India':
voice = 'Aditi'
elif country == 'Italy':
voice = 'Carla'
elif country == 'Japan':
voice = 'Mizuki'
elif country == 'France':
voice = 'Celine'
elif country == 'Spain':
voice = 'Conchita'
elif country == 'United States of America':
voice = 'Joanna'
connection = is_connected()
args = sys.argv
if connection:
print('Connected to the internet')
if len(args) == 3:
voice = args[2]
print('Forcing accent')
else:
print('Detected Country: ' + country)
tts = Polly(voice)
tts.say(args[1])
else:
print('Internet connection unavailable')
subprocess.call(["espeak", '"' + str(args[1]) + '"'])