Update app.py
Browse files
app.py
CHANGED
@@ -18,10 +18,13 @@ def install_fairseq():
|
|
18 |
subprocess.check_call(["pip", "install", "fairseq"])
|
19 |
subprocess.check_call(["pip", "install", "sentencepiece"])
|
20 |
subprocess.check_call(["pip", "install", "soundfile"])
|
|
|
21 |
return "fairseq successfully installed!"
|
22 |
except subprocess.CalledProcessError as e:
|
23 |
return f"An error occurred while installing fairseq: {str(e)}"
|
24 |
|
|
|
|
|
25 |
def convert_audio_to_16k_wav(audio_input):
|
26 |
sound = AudioSegment.from_file(audio_input)
|
27 |
sample_rate = sound.frame_rate
|
@@ -48,30 +51,37 @@ def run_my_code(input_text, language):
|
|
48 |
data_root=""
|
49 |
model_checkpoint=""
|
50 |
d_r=""
|
|
|
51 |
|
52 |
if(language=="Hindi"):
|
53 |
model_checkpoint = "./models/hi_m.pt"
|
54 |
data_root="./lang/hi/"
|
|
|
55 |
|
56 |
if(language=="Gujrati"):
|
57 |
model_checkpoint = "./models/gj_m.pt"
|
58 |
data_root="./lang/gj/"
|
|
|
59 |
|
60 |
if(language=="Bengali"):
|
61 |
model_checkpoint = "./models/bn_m.pt"
|
62 |
-
data_root="./lang/bn/"
|
|
|
63 |
|
64 |
if(language=="Nepali"):
|
65 |
model_checkpoint = "./models/ne_m.pt"
|
66 |
data_root="./lang/ne/"
|
|
|
67 |
|
68 |
if(language=="Tamil"):
|
69 |
model_checkpoint = "./models/tm_m.pt"
|
70 |
data_root="./lang/tm/"
|
|
|
71 |
|
72 |
if(language=="Marathi"):
|
73 |
model_checkpoint = "./models/mt_m.pt"
|
74 |
-
data_root="./lang/mt/"
|
|
|
75 |
|
76 |
#os.system(f"cp {hi_wav} {data_root}data/tst-COMMON/wav/test.wav")
|
77 |
f = open('input.txt', 'w')
|
@@ -97,14 +107,20 @@ def run_my_code(input_text, language):
|
|
97 |
output_text=i.split("\t")[2]
|
98 |
break
|
99 |
|
100 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
101 |
f = open('input.txt', 'w')
|
102 |
f.write("")
|
103 |
|
104 |
f = open('input.txt', 'r')
|
105 |
content = f. read()
|
106 |
print(content)
|
107 |
-
return output_text
|
108 |
|
109 |
install_fairseq()
|
110 |
|
@@ -123,7 +139,7 @@ output_textbox = gr.outputs.Textbox(label="Translated Text")
|
|
123 |
iface = gr.Interface(
|
124 |
fn=run_my_code,
|
125 |
inputs=[gr.inputs.Audio(source="microphone", type="filepath", label="Record something (in American English accent)"), gr.inputs.Radio(["Hindi", "Gujrati", "Bengali", "Tamil", "Nepali", "Marathi"], label="Language")],
|
126 |
-
outputs=output_textbox,
|
127 |
title="English to Indic Language Translator")
|
128 |
|
129 |
# Launch the interface
|
|
|
18 |
subprocess.check_call(["pip", "install", "fairseq"])
|
19 |
subprocess.check_call(["pip", "install", "sentencepiece"])
|
20 |
subprocess.check_call(["pip", "install", "soundfile"])
|
21 |
+
subprocess.check_call(["pip", "install", "gTTS"])
|
22 |
return "fairseq successfully installed!"
|
23 |
except subprocess.CalledProcessError as e:
|
24 |
return f"An error occurred while installing fairseq: {str(e)}"
|
25 |
|
26 |
+
from gtts import gTTS
|
27 |
+
|
28 |
def convert_audio_to_16k_wav(audio_input):
|
29 |
sound = AudioSegment.from_file(audio_input)
|
30 |
sample_rate = sound.frame_rate
|
|
|
51 |
data_root=""
|
52 |
model_checkpoint=""
|
53 |
d_r=""
|
54 |
+
lang=''
|
55 |
|
56 |
if(language=="Hindi"):
|
57 |
model_checkpoint = "./models/hi_m.pt"
|
58 |
data_root="./lang/hi/"
|
59 |
+
lang='hi'
|
60 |
|
61 |
if(language=="Gujrati"):
|
62 |
model_checkpoint = "./models/gj_m.pt"
|
63 |
data_root="./lang/gj/"
|
64 |
+
lang='gu'
|
65 |
|
66 |
if(language=="Bengali"):
|
67 |
model_checkpoint = "./models/bn_m.pt"
|
68 |
+
data_root="./lang/bn/"
|
69 |
+
lang='bn'
|
70 |
|
71 |
if(language=="Nepali"):
|
72 |
model_checkpoint = "./models/ne_m.pt"
|
73 |
data_root="./lang/ne/"
|
74 |
+
lang='ne'
|
75 |
|
76 |
if(language=="Tamil"):
|
77 |
model_checkpoint = "./models/tm_m.pt"
|
78 |
data_root="./lang/tm/"
|
79 |
+
lang='ta'
|
80 |
|
81 |
if(language=="Marathi"):
|
82 |
model_checkpoint = "./models/mt_m.pt"
|
83 |
+
data_root="./lang/mt/"
|
84 |
+
lang='mr'
|
85 |
|
86 |
#os.system(f"cp {hi_wav} {data_root}data/tst-COMMON/wav/test.wav")
|
87 |
f = open('input.txt', 'w')
|
|
|
107 |
output_text=i.split("\t")[2]
|
108 |
break
|
109 |
|
110 |
+
output_audio = "output_audio.mp3"
|
111 |
+
tts = gTTS(text=output_text, lang=lang)
|
112 |
+
tts.save(output_audio)
|
113 |
+
|
114 |
+
|
115 |
+
|
116 |
+
#os.system(f"rm test.wav")
|
117 |
f = open('input.txt', 'w')
|
118 |
f.write("")
|
119 |
|
120 |
f = open('input.txt', 'r')
|
121 |
content = f. read()
|
122 |
print(content)
|
123 |
+
return output_text, output_audio
|
124 |
|
125 |
install_fairseq()
|
126 |
|
|
|
139 |
iface = gr.Interface(
|
140 |
fn=run_my_code,
|
141 |
inputs=[gr.inputs.Audio(source="microphone", type="filepath", label="Record something (in American English accent)"), gr.inputs.Radio(["Hindi", "Gujrati", "Bengali", "Tamil", "Nepali", "Marathi"], label="Language")],
|
142 |
+
outputs=[output_textbox, gr.outputs.Audio(label="Output speech", type="filepath", live=True)],
|
143 |
title="English to Indic Language Translator")
|
144 |
|
145 |
# Launch the interface
|