Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,51 +3,86 @@ from gtts import gTTS
|
|
3 |
from pydub import AudioSegment
|
4 |
from io import BytesIO
|
5 |
|
6 |
-
|
7 |
-
|
8 |
-
#
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
audio_file = BytesIO()
|
22 |
tts.write_to_fp(audio_file)
|
23 |
audio_file.seek(0)
|
24 |
tts_audio = AudioSegment.from_file(audio_file, format="mp3")
|
25 |
-
|
|
|
26 |
|
27 |
-
#
|
28 |
output_file = "combined_output.mp3"
|
29 |
combined_audio.export(output_file, format="mp3")
|
30 |
|
31 |
return output_file
|
32 |
|
33 |
-
# Step 2: Create Gradio interface
|
34 |
with gr.Blocks() as demo:
|
35 |
-
gr.Markdown("## Multilingual TTS: Generate a Single Audio File")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
|
37 |
with gr.Row():
|
38 |
-
|
39 |
-
british_english_input = gr.Textbox(label="Enter British English Text:", placeholder="Hello (British)")
|
40 |
-
american_english_input = gr.Textbox(label="Enter American English Text:", placeholder="Hello (American)")
|
41 |
|
42 |
output_audio = gr.Audio(label="Generated Speech", type="filepath")
|
43 |
generate_button = gr.Button("Generate Speech")
|
44 |
|
45 |
generate_button.click(
|
46 |
multilingual_tts,
|
47 |
-
inputs=[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
outputs=output_audio
|
49 |
)
|
50 |
|
51 |
-
# Run the app
|
52 |
if __name__ == "__main__":
|
53 |
demo.launch()
|
|
|
3 |
from pydub import AudioSegment
|
4 |
from io import BytesIO
|
5 |
|
6 |
+
def multilingual_tts(
|
7 |
+
korean_text,
|
8 |
+
british_text, # ๊ธฐ์กด ์๊ตญ์ ์
๋ ฅ๋
|
9 |
+
american_text, # ๊ธฐ์กด ๋ฏธ๊ตญ์ ์
๋ ฅ๋
|
10 |
+
british_text_add1, # ์ถ๊ฐ ์๊ตญ์ ์
๋ ฅ๋ 1
|
11 |
+
british_text_add2, # ์ถ๊ฐ ์๊ตญ์ ์
๋ ฅ๋ 2
|
12 |
+
australian_text_add1, # ์ถ๊ฐ ํธ์ฃผ์ ์
๋ ฅ๋ 1
|
13 |
+
australian_text_add2, # ์ถ๊ฐ ํธ์ฃผ์ ์
๋ ฅ๋ 2
|
14 |
+
american_text_add1 # ์ถ๊ฐ ๋ฏธ๊ตญ์ ์
๋ ฅ๋ 1
|
15 |
+
):
|
16 |
+
# ๊ฐ ์์ฑ์ ๋ํด (์ธ์ด ์ฝ๋, tld, ํ
์คํธ) ํํ์ ๋ฆฌ์คํธ์ ์ ์ฅํฉ๋๋ค.
|
17 |
+
voices = [
|
18 |
+
("ko", "com", korean_text), # ํ๊ตญ์ด
|
19 |
+
("en", "co.uk", british_text), # ๊ธฐ์กด ์๊ตญ์
|
20 |
+
("en", "com", american_text), # ๊ธฐ์กด ๋ฏธ๊ตญ์
|
21 |
+
("en", "co.uk", british_text_add1), # ์ถ๊ฐ ์๊ตญ์ 1
|
22 |
+
("en", "co.uk", british_text_add2), # ์ถ๊ฐ ์๊ตญ์ 2
|
23 |
+
("en", "com.au", australian_text_add1), # ์ถ๊ฐ ํธ์ฃผ์ 1
|
24 |
+
("en", "com.au", australian_text_add2), # ์ถ๊ฐ ํธ์ฃผ์ 2
|
25 |
+
("en", "com", american_text_add1) # ์ถ๊ฐ ๋ฏธ๊ตญ์ 1
|
26 |
+
]
|
27 |
+
|
28 |
+
combined_audio = AudioSegment.silent(duration=0) # ๋น ์ค๋์ค
|
29 |
+
|
30 |
+
for lang, tld, text in voices:
|
31 |
+
if text.strip(): # ํ
์คํธ๊ฐ ์
๋ ฅ๋์ด ์์ ๋๋ง ์ฒ๋ฆฌ
|
32 |
+
tts = gTTS(text, lang=lang, tld=tld)
|
33 |
audio_file = BytesIO()
|
34 |
tts.write_to_fp(audio_file)
|
35 |
audio_file.seek(0)
|
36 |
tts_audio = AudioSegment.from_file(audio_file, format="mp3")
|
37 |
+
# ๊ฐ ์์ฑ ์ฌ์ด์ 500ms์ ์นจ๋ฌต ์ถ๊ฐ
|
38 |
+
combined_audio += tts_audio + AudioSegment.silent(duration=500)
|
39 |
|
40 |
+
# ์ต์ข
๊ฒฐํฉ๋ ์ค๋์ค๋ฅผ mp3 ํ์ผ๋ก ์ ์ฅ
|
41 |
output_file = "combined_output.mp3"
|
42 |
combined_audio.export(output_file, format="mp3")
|
43 |
|
44 |
return output_file
|
45 |
|
|
|
46 |
with gr.Blocks() as demo:
|
47 |
+
gr.Markdown("## Multilingual TTS: Generate a Single Audio File (์ด 8๊ฐ ์์ฑ)")
|
48 |
+
|
49 |
+
# ํ๊ตญ์ด ์
๋ ฅ๋
|
50 |
+
korean_input = gr.Textbox(label="Enter Korean Text:", placeholder="์๋
ํ์ธ์")
|
51 |
+
|
52 |
+
# ๊ธฐ์กด ์์ด ์
๋ ฅ๋ (์๊ตญ, ๋ฏธ๊ตญ)
|
53 |
+
with gr.Row():
|
54 |
+
british_input = gr.Textbox(label="Enter British English Text:", placeholder="Hello (British)")
|
55 |
+
american_input = gr.Textbox(label="Enter American English Text:", placeholder="Hello (American)")
|
56 |
+
|
57 |
+
# ์ถ๊ฐ ์์ด ์
๋ ฅ๋
|
58 |
+
with gr.Row():
|
59 |
+
british_input_add1 = gr.Textbox(label="Enter Additional British English Text 1:", placeholder="Hi there (British)")
|
60 |
+
british_input_add2 = gr.Textbox(label="Enter Additional British English Text 2:", placeholder="Good day (British)")
|
61 |
+
|
62 |
+
with gr.Row():
|
63 |
+
australian_input_add1 = gr.Textbox(label="Enter Additional Australian English Text 1:", placeholder="G'day (Australian)")
|
64 |
+
australian_input_add2 = gr.Textbox(label="Enter Additional Australian English Text 2:", placeholder="How ya going? (Australian)")
|
65 |
|
66 |
with gr.Row():
|
67 |
+
american_input_add1 = gr.Textbox(label="Enter Additional American English Text:", placeholder="Hey (American)")
|
|
|
|
|
68 |
|
69 |
output_audio = gr.Audio(label="Generated Speech", type="filepath")
|
70 |
generate_button = gr.Button("Generate Speech")
|
71 |
|
72 |
generate_button.click(
|
73 |
multilingual_tts,
|
74 |
+
inputs=[
|
75 |
+
korean_input,
|
76 |
+
british_input,
|
77 |
+
american_input,
|
78 |
+
british_input_add1,
|
79 |
+
british_input_add2,
|
80 |
+
australian_input_add1,
|
81 |
+
australian_input_add2,
|
82 |
+
american_input_add1
|
83 |
+
],
|
84 |
outputs=output_audio
|
85 |
)
|
86 |
|
|
|
87 |
if __name__ == "__main__":
|
88 |
demo.launch()
|