-
Notifications
You must be signed in to change notification settings - Fork 0
/
Multilanguage.py
196 lines (192 loc) · 6.31 KB
/
Multilanguage.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
import speech_recognition as sr
import requests as r
from bs4 import BeautifulSoup as bs
from googletrans import Translator
translator = Translator()
recognizer=sr.Recognizer()
microphone = sr.Microphone()
res=r.get("https://cloud.google.com/speech-to-text/docs/languages")
soup=bs(res.content,'html.parser')
LANGUAGES = {'af': 'afrikaans','sq': 'albanian','am': 'amharic',
'ar': 'arabic',
'hy': 'armenian',
'az': 'azerbaijani',
'eu': 'basque',
'be': 'belarusian',
'bn': 'bengali',
'bs': 'bosnian',
'bg': 'bulgarian',
'ca': 'catalan',
'ceb': 'cebuano',
'ny': 'chichewa',
'zh-cn': 'chinese (simplified)',
'zh-tw': 'chinese (traditional)',
'co': 'corsican',
'hr': 'croatian',
'cs': 'czech',
'da': 'danish',
'nl': 'dutch',
'en': 'english',
'eo': 'esperanto',
'et': 'estonian',
'tl': 'filipino',
'fi': 'finnish',
'fr': 'french',
'fy': 'frisian',
'gl': 'galician',
'ka': 'georgian',
'de': 'german',
'el': 'greek',
'gu': 'gujarati',
'ht': 'haitian creole',
'ha': 'hausa',
'haw': 'hawaiian',
'iw': 'hebrew',
'hi': 'hindi',
'hmn': 'hmong',
'hu': 'hungarian',
'is': 'icelandic',
'ig': 'igbo',
'id': 'indonesian',
'ga': 'irish',
'it': 'italian',
'ja': 'japanese',
'jw': 'javanese',
'kn': 'kannada',
'kk': 'kazakh',
'km': 'khmer',
'ko': 'korean',
'ku': 'kurdish (kurmanji)',
'ky': 'kyrgyz',
'lo': 'lao',
'la': 'latin',
'lv': 'latvian',
'lt': 'lithuanian',
'lb': 'luxembourgish',
'mk': 'macedonian',
'mg': 'malagasy',
'ms': 'malay',
'ml': 'malayalam',
'mt': 'maltese',
'mi': 'maori',
'mr': 'marathi',
'mn': 'mongolian',
'my': 'myanmar (burmese)',
'ne': 'nepali',
'no': 'norwegian',
'ps': 'pashto',
'fa': 'persian',
'pl': 'polish',
'pt': 'portuguese','pa': 'punjabi','ro': 'romanian','ru': 'russian','sm': 'samoan','gd': 'scots gaelic','sr': 'serbian','st': 'sesotho','sn': 'shona','sd': 'sindhi','si': 'sinhala','sk': 'slovak','sl': 'slovenian','so': 'somali','es': 'spanish','su': 'sundanese','sw': 'swahili','sv': 'swedish','tg': 'tajik','ta': 'tamil','te': 'telugu','th': 'thai','tr': 'turkish','uk': 'ukrainian','ur': 'urdu','uz': 'uzbek','vi': 'vietnamese','cy': 'welsh','xh': 'xhosa','yi': 'yiddish','yo': 'yoruba','zu': 'zulu','fil': 'Filipino','he': 'Hebrew'
}
LANGCODES = dict(map(reversed, LANGUAGES.items()))
temp=[j for j in range(2,360,3)]
x=0
d=list()
lang=[]
for i in soup.select('div table tbody tr td'):
if x in temp:
d=d+list(i)
lang.append(d)
d=list()
else:
d=d+list(i)
x+=1
d=dict()
x=0
for i in lang:
d[i[2]]=[x,i[1]]
x+=1
#Language for speech_recognition
temp_d=dict()
for i,j in d.items():
temp_d[i.split()[0].lower()]=j[1].split("-")[0]
print("Please Enter Ist User Name:")
user1=input()
print("Please Enter 2nd User Name: ")
user2=input()
for i,j in d.items():
print("Language:",i,"Index:",j[0])
print(user1,"select your Perfered Language,Please select the index")
index1=int(input())
final1=None
for i,j in d.items():
if j[0]==index1:
final1=j[1]
lang1=i
print(user2,"select your Perfered Language,Please select the index")
index2=int(input())
final2=None
for i,j in d.items():
if j[0]==index2:
final2=j[1]
lang2=i
temp_l=dict()
for i,j in LANGCODES.items():
temp_l[i.split()[0].lower()]=j
i=2
print(user1,"Has select Language:",lang1)#,"and Language code:",final1,"and",final1.split("-")[0],"or",temp_l[lang1.split()[0].lower()])
print(user2,"Has select language:",lang2)#,"and Language code:",final2,'and',final2.split("-")[0],"or",temp_l[lang2.split()[0].lower()])
while 1:
with microphone as source:
if i%2==0:
print(user1,"Please say something:")
recognizer.adjust_for_ambient_noise(source)
audio = recognizer.listen(source)
# set up the response object
response = {
"success": True,
"error": None,
"transcription": None
}
# try recognizing the speech in the recording
# if a RequestError or UnknownValueError exception is caught,
# update the response object accordingly
try:
response["transcription"] = recognizer.recognize_google(audio,language=final1)
except sr.RequestError:
# API was unreachable or unresponsive
print("API was unreachable or unresponsive,Please try again")
response["success"] = False
response["error"] = "API unavailable"
continue
except sr.UnknownValueError:
# speech was unintelligible
response["error"] = "Unable to recognize speech"
print("Sorry didn't get..Try Again")
continue
print(response['transcription'])
x=translator.translate(response['transcription'],dest=final2.split("-")[0])
print(user1,"Has said:",x.text)
else :
print(user2,"Please say something:")
recognizer.adjust_for_ambient_noise(source)
audio = recognizer.listen(source)
# set up the response object
response = {
"success": True,
"error": None,
"transcription": None
}
# try recognizing the speech in the recording
# if a RequestError or UnknownValueError exception is caught,
# update the response object accordingly
try:
response["transcription"] = recognizer.recognize_google(audio,language=final2)
except sr.RequestError:
# API was unreachable or unresponsive
print("API was unreachable or unresponsive,Please try again")
response["success"] = False
response["error"] = "API unavailable"
continue
except sr.UnknownValueError:
# speech was unintelligible
response["error"] = "Unable to recognize speech"
print("Sorry didn't get..Try Again")
continue
print(response['transcription'])
x=translator.translate(response['transcription'],dest=final1.split("-")[0])
print(user2,"Has said:",x.text)
i+=1
if i>=6:
break