Spaces:
Running
Running
Chandrabhan01
commited on
Commit
·
779af4f
1
Parent(s):
d4adc8f
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from gtts import gTTS
|
2 |
+
import gradio as gr
|
3 |
+
from googletrans import Translator
|
4 |
+
|
5 |
+
lang = {'Afrikaans': 'af','Arabic':'ar','Bulgarian':'bg','Bengali':'bn','Bosnian':'bs',
|
6 |
+
'Catalan':'ca','Czech':'cs','Danish':'da','German':'de','Greek':'el','English':'en',
|
7 |
+
'Spanish':'es','Estonian':'et','Finnish':'fi','French':'fr','Gujarati':'gu','Hindi':'hi',
|
8 |
+
'Croatian':'hr','Hungarian':'hu','Indonesian':'id','Icelandic':'is','Italian':'it',
|
9 |
+
'Hebrew':'iw','Japanese':'ja','Javanese':'jw','Khmer':'km','Kannada':'kn','Korean':'ko',
|
10 |
+
'Latin':'la','Latvian':'lv','Malayalam':'ml','Marathi':'mr','Malay':'ms',
|
11 |
+
'Myanmar (Burmese)':'my','Nepali':'ne', 'Dutch':'nl','Norwegian':'no',
|
12 |
+
'Polish':'pl','Portuguese':'pt','Romanian':'ro','Russian':'ru','Sinhala':'si',
|
13 |
+
'Slovak':'sk', 'Albanian':'sq','Serbian':'sr','Sundanese':'su','Swedish':'sv',
|
14 |
+
'Swahili':'sw','Tamil':'ta','Telugu':'te','Thai':'th','Filipino':'tl','Turkish':'tr',
|
15 |
+
'Ukrainian':'uk','Urdu':'ur','Vietnamese':'vi','Chinese (Simplified)':'zh-CN',
|
16 |
+
'Chinese (Mandarin/Taiwan)':'zh-TW',
|
17 |
+
'Chinese (Mandarin)':'zh'}
|
18 |
+
|
19 |
+
tld = {'English(Australia)':'com.au', 'English (United Kingdom)':'co.uk',
|
20 |
+
'English (United States)':'us', 'English (Canada)':'ca','English (India)':'co.in',
|
21 |
+
'English (Ireland)':'ie','English (South Africa)':'co.za','French (Canada)':'ca',
|
22 |
+
'French (France)':'fr','Portuguese (Brazil)':'com.br','Portuguese (Portugal)':'pt',
|
23 |
+
'Spanish (Mexico)':'com.mx','Spanish (Spain)':'es','Spanish (United States)':'us'}
|
24 |
+
|
25 |
+
def T2TConversion(sentence, language):
|
26 |
+
translator = Translator()
|
27 |
+
translation = translator.translate(sentence, dest = lang[language])
|
28 |
+
return translation.text
|
29 |
+
|
30 |
+
def convert_text(Text, Accent):
|
31 |
+
""" Performs Text-To-Speech provided language and accent.] """
|
32 |
+
|
33 |
+
tts = gTTS(Text, tld[Accent])
|
34 |
+
tts.save('tts.mp3')
|
35 |
+
with open('tts.mp3') as fp:
|
36 |
+
return fp.name
|
37 |
+
|
38 |
+
def start():
|
39 |
+
it_1 = gr.Interface(fn = convert_text,
|
40 |
+
inputs = [
|
41 |
+
gr.TextArea(label = 'The Text to be Converted to Audio'),
|
42 |
+
gr.Dropdown([key for key,_ in tld.items()])],
|
43 |
+
outputs = gr.Audio(),
|
44 |
+
title = 'A Text-To-Speech Converter for Low Resource Languages',
|
45 |
+
description= 'Support over 50 languages !',
|
46 |
+
article= 'How does it work ? Just write a sentence (in target language) in the space provided and select the accent and press submit. That is it. Wait and Enjoy.')
|
47 |
+
|
48 |
+
it_2 = gr.Interface(fn=T2TConversion,
|
49 |
+
inputs = [
|
50 |
+
gr.Text(label='Write a sentence in English'),
|
51 |
+
gr.Dropdown([key for key,_ in lang.items()])],
|
52 |
+
outputs= gr.Text(label='The Converted Text'),
|
53 |
+
title = 'Translation from English',
|
54 |
+
description='Write a sentence in english and convert to other languages for speech synthesis',
|
55 |
+
article='What if you do not have a sentence in a particular language? Just write the sentence in english and let us do the magic.')
|
56 |
+
|
57 |
+
demo = gr.TabbedInterface([it_1,it_2],['Speech Synthesis', 'Sentence Translation'])
|
58 |
+
demo.launch()
|
59 |
+
|
60 |
+
start()
|