Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,37 +1,53 @@
|
|
1 |
import gradio as gr
|
2 |
from gtts import gTTS
|
3 |
-
from
|
|
|
|
|
4 |
|
5 |
-
# Step 1: Define a function to
|
6 |
-
def
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
# Step 2: Create Gradio interface
|
21 |
with gr.Blocks() as demo:
|
22 |
-
gr.Markdown("##
|
23 |
|
24 |
with gr.Row():
|
25 |
-
|
|
|
|
|
|
|
26 |
|
27 |
-
output_text = gr.Textbox(label="Status")
|
28 |
output_audio = gr.Audio(label="Generated Speech", type="filepath")
|
29 |
generate_button = gr.Button("Generate Speech")
|
30 |
|
31 |
generate_button.click(
|
32 |
-
|
33 |
-
inputs=
|
34 |
-
outputs=
|
35 |
)
|
36 |
|
37 |
# Run the app
|
|
|
1 |
import gradio as gr
|
2 |
from gtts import gTTS
|
3 |
+
from pydub import AudioSegment
|
4 |
+
from pydub.playback import play
|
5 |
+
from io import BytesIO
|
6 |
|
7 |
+
# Step 1: Define a function to generate and merge TTS audio for multiple languages
|
8 |
+
def multilingual_tts(korean_text, english_text, russian_text, bulgarian_text):
|
9 |
+
# Language mapping
|
10 |
+
texts = {
|
11 |
+
"ko": korean_text,
|
12 |
+
"en": english_text,
|
13 |
+
"ru": russian_text,
|
14 |
+
"bg": bulgarian_text,
|
15 |
+
}
|
16 |
+
|
17 |
+
combined_audio = AudioSegment.silent(duration=0) # Empty audio to start
|
18 |
+
|
19 |
+
for lang, text in texts.items():
|
20 |
+
if text.strip(): # Process only if text is provided
|
21 |
+
tts = gTTS(text, lang=lang)
|
22 |
+
audio_file = BytesIO()
|
23 |
+
tts.write_to_fp(audio_file)
|
24 |
+
audio_file.seek(0)
|
25 |
+
tts_audio = AudioSegment.from_file(audio_file, format="mp3")
|
26 |
+
combined_audio += tts_audio + AudioSegment.silent(duration=500) # Add silence between languages
|
27 |
+
|
28 |
+
# Save combined audio to a file
|
29 |
+
output_file = "combined_output.mp3"
|
30 |
+
combined_audio.export(output_file, format="mp3")
|
31 |
+
|
32 |
+
return output_file
|
33 |
|
34 |
# Step 2: Create Gradio interface
|
35 |
with gr.Blocks() as demo:
|
36 |
+
gr.Markdown("## Multilingual TTS: Generate a Single Audio File")
|
37 |
|
38 |
with gr.Row():
|
39 |
+
korean_input = gr.Textbox(label="Enter Korean Text:", placeholder="안녕하세요")
|
40 |
+
english_input = gr.Textbox(label="Enter English Text:", placeholder="Hello")
|
41 |
+
russian_input = gr.Textbox(label="Enter Russian Text:", placeholder="Привет")
|
42 |
+
bulgarian_input = gr.Textbox(label="Enter Bulgarian Text:", placeholder="Здравейте")
|
43 |
|
|
|
44 |
output_audio = gr.Audio(label="Generated Speech", type="filepath")
|
45 |
generate_button = gr.Button("Generate Speech")
|
46 |
|
47 |
generate_button.click(
|
48 |
+
multilingual_tts,
|
49 |
+
inputs=[korean_input, english_input, russian_input, bulgarian_input],
|
50 |
+
outputs=output_audio
|
51 |
)
|
52 |
|
53 |
# Run the app
|