Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -3,36 +3,45 @@ from gtts import gTTS
|
|
3 |
from pydub import AudioSegment
|
4 |
from io import BytesIO
|
5 |
|
6 |
-
def
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
):
|
18 |
-
# ๊ฐ
|
19 |
-
|
20 |
-
("
|
21 |
-
("en", "
|
22 |
-
("en", "com"
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
(
|
28 |
-
(
|
29 |
-
(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
]
|
31 |
|
32 |
-
combined_audio = AudioSegment.silent(duration=0) # ๋น ์ค๋์ค
|
33 |
|
34 |
-
|
35 |
-
|
|
|
|
|
36 |
tts = gTTS(text, lang=lang, tld=tld)
|
37 |
audio_file = BytesIO()
|
38 |
tts.write_to_fp(audio_file)
|
@@ -44,57 +53,70 @@ def multilingual_tts(
|
|
44 |
# ์ต์ข
๊ฒฐํฉ๋ ์ค๋์ค๋ฅผ mp3 ํ์ผ๋ก ์ ์ฅ
|
45 |
output_file = "combined_output.mp3"
|
46 |
combined_audio.export(output_file, format="mp3")
|
47 |
-
|
48 |
return output_file
|
49 |
|
50 |
with gr.Blocks() as demo:
|
51 |
-
gr.Markdown("##
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
|
53 |
-
|
54 |
-
|
|
|
|
|
|
|
|
|
|
|
55 |
|
56 |
-
# ๊ธฐ์กด ์์ด ์
๋ ฅ๋ (์๊ตญ์, ๋ฏธ๊ตญ์)
|
57 |
with gr.Row():
|
58 |
-
|
59 |
-
|
60 |
|
61 |
-
# ์ถ๊ฐ ์์ด ์
๋ ฅ๋ (์ถ๊ฐ ์๊ตญ์)
|
62 |
with gr.Row():
|
63 |
-
|
64 |
-
|
65 |
|
66 |
-
# ์ถ๊ฐ ์์ด ์
๋ ฅ๋ (์ถ๊ฐ ํธ์ฃผ์)
|
67 |
with gr.Row():
|
68 |
-
|
69 |
-
|
70 |
|
71 |
-
# ์ถ๊ฐ ์์ด ์
๋ ฅ๋ (์ถ๊ฐ ๋ฏธ๊ตญ์ ๋ฐ ์ถ๊ฐ ์์ด)
|
72 |
with gr.Row():
|
73 |
-
|
74 |
-
|
75 |
|
76 |
-
|
77 |
-
|
|
|
|
|
|
|
|
|
|
|
78 |
|
79 |
output_audio = gr.Audio(label="Generated Speech", type="filepath")
|
80 |
generate_button = gr.Button("Generate Speech")
|
81 |
|
82 |
generate_button.click(
|
83 |
-
|
84 |
inputs=[
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
],
|
96 |
outputs=output_audio
|
97 |
)
|
98 |
|
99 |
if __name__ == "__main__":
|
100 |
-
demo.launch()
|
|
|
3 |
from pydub import AudioSegment
|
4 |
from io import BytesIO
|
5 |
|
6 |
+
def custom_tts(
|
7 |
+
text1, accent1,
|
8 |
+
text2, accent2,
|
9 |
+
text3, accent3,
|
10 |
+
text4, accent4,
|
11 |
+
text5, accent5,
|
12 |
+
text6, accent6,
|
13 |
+
text7, accent7,
|
14 |
+
text8, accent8,
|
15 |
+
text9, accent9,
|
16 |
+
text10, accent10
|
17 |
):
|
18 |
+
# ๊ฐ ์
์ผํธ์ ๋ฐ๋ฅธ ์ธ์ด ์ฝ๋์ tld ์ค์
|
19 |
+
accent_mapping = {
|
20 |
+
"British": ("en", "co.uk"),
|
21 |
+
"American": ("en", "com"),
|
22 |
+
"Australian": ("en", "com.au")
|
23 |
+
}
|
24 |
+
|
25 |
+
# 10๊ฐ์ ๋ํ๋ฌธ๊ณผ ์ ํ๋ ์
์ผํธ๋ฅผ ํํ ๋ฆฌ์คํธ๋ก ๊ตฌ์ฑํฉ๋๋ค.
|
26 |
+
dialogues = [
|
27 |
+
(text1, accent1),
|
28 |
+
(text2, accent2),
|
29 |
+
(text3, accent3),
|
30 |
+
(text4, accent4),
|
31 |
+
(text5, accent5),
|
32 |
+
(text6, accent6),
|
33 |
+
(text7, accent7),
|
34 |
+
(text8, accent8),
|
35 |
+
(text9, accent9),
|
36 |
+
(text10, accent10)
|
37 |
]
|
38 |
|
39 |
+
combined_audio = AudioSegment.silent(duration=0) # ์ด๊ธฐ ๋น ์ค๋์ค
|
40 |
|
41 |
+
# ๊ฐ ๋ํ๋ฌธ์ ๋ํด ์์ฑ ์์ฑ ํ ๊ฒฐํฉ
|
42 |
+
for text, accent in dialogues:
|
43 |
+
if text.strip(): # ํ
์คํธ๊ฐ ๋น์ด์์ง ์์ ๊ฒฝ์ฐ์๋ง ์ฒ๋ฆฌ
|
44 |
+
lang, tld = accent_mapping.get(accent, ("en", "com"))
|
45 |
tts = gTTS(text, lang=lang, tld=tld)
|
46 |
audio_file = BytesIO()
|
47 |
tts.write_to_fp(audio_file)
|
|
|
53 |
# ์ต์ข
๊ฒฐํฉ๋ ์ค๋์ค๋ฅผ mp3 ํ์ผ๋ก ์ ์ฅ
|
54 |
output_file = "combined_output.mp3"
|
55 |
combined_audio.export(output_file, format="mp3")
|
|
|
56 |
return output_file
|
57 |
|
58 |
with gr.Blocks() as demo:
|
59 |
+
gr.Markdown("## Custom TTS: 10๊ฐ์ ๋ํ๋ฌธ ์
๋ ฅ๋์์ ์
์ผํธ๋ฅผ ์ ํํ์ฌ ์์ฑ ์์ฑํ๊ธฐ")
|
60 |
+
|
61 |
+
with gr.Row():
|
62 |
+
text1 = gr.Textbox(label="Dialogue 1", placeholder="Enter text for Dialogue 1")
|
63 |
+
accent1 = gr.Dropdown(label="Accent for Dialogue 1", choices=["British", "American", "Australian"], value="British")
|
64 |
+
|
65 |
+
with gr.Row():
|
66 |
+
text2 = gr.Textbox(label="Dialogue 2", placeholder="Enter text for Dialogue 2")
|
67 |
+
accent2 = gr.Dropdown(label="Accent for Dialogue 2", choices=["British", "American", "Australian"], value="British")
|
68 |
|
69 |
+
with gr.Row():
|
70 |
+
text3 = gr.Textbox(label="Dialogue 3", placeholder="Enter text for Dialogue 3")
|
71 |
+
accent3 = gr.Dropdown(label="Accent for Dialogue 3", choices=["British", "American", "Australian"], value="British")
|
72 |
+
|
73 |
+
with gr.Row():
|
74 |
+
text4 = gr.Textbox(label="Dialogue 4", placeholder="Enter text for Dialogue 4")
|
75 |
+
accent4 = gr.Dropdown(label="Accent for Dialogue 4", choices=["British", "American", "Australian"], value="British")
|
76 |
|
|
|
77 |
with gr.Row():
|
78 |
+
text5 = gr.Textbox(label="Dialogue 5", placeholder="Enter text for Dialogue 5")
|
79 |
+
accent5 = gr.Dropdown(label="Accent for Dialogue 5", choices=["British", "American", "Australian"], value="British")
|
80 |
|
|
|
81 |
with gr.Row():
|
82 |
+
text6 = gr.Textbox(label="Dialogue 6", placeholder="Enter text for Dialogue 6")
|
83 |
+
accent6 = gr.Dropdown(label="Accent for Dialogue 6", choices=["British", "American", "Australian"], value="British")
|
84 |
|
|
|
85 |
with gr.Row():
|
86 |
+
text7 = gr.Textbox(label="Dialogue 7", placeholder="Enter text for Dialogue 7")
|
87 |
+
accent7 = gr.Dropdown(label="Accent for Dialogue 7", choices=["British", "American", "Australian"], value="British")
|
88 |
|
|
|
89 |
with gr.Row():
|
90 |
+
text8 = gr.Textbox(label="Dialogue 8", placeholder="Enter text for Dialogue 8")
|
91 |
+
accent8 = gr.Dropdown(label="Accent for Dialogue 8", choices=["British", "American", "Australian"], value="British")
|
92 |
|
93 |
+
with gr.Row():
|
94 |
+
text9 = gr.Textbox(label="Dialogue 9", placeholder="Enter text for Dialogue 9")
|
95 |
+
accent9 = gr.Dropdown(label="Accent for Dialogue 9", choices=["British", "American", "Australian"], value="British")
|
96 |
+
|
97 |
+
with gr.Row():
|
98 |
+
text10 = gr.Textbox(label="Dialogue 10", placeholder="Enter text for Dialogue 10")
|
99 |
+
accent10 = gr.Dropdown(label="Accent for Dialogue 10", choices=["British", "American", "Australian"], value="British")
|
100 |
|
101 |
output_audio = gr.Audio(label="Generated Speech", type="filepath")
|
102 |
generate_button = gr.Button("Generate Speech")
|
103 |
|
104 |
generate_button.click(
|
105 |
+
custom_tts,
|
106 |
inputs=[
|
107 |
+
text1, accent1,
|
108 |
+
text2, accent2,
|
109 |
+
text3, accent3,
|
110 |
+
text4, accent4,
|
111 |
+
text5, accent5,
|
112 |
+
text6, accent6,
|
113 |
+
text7, accent7,
|
114 |
+
text8, accent8,
|
115 |
+
text9, accent9,
|
116 |
+
text10, accent10
|
117 |
+
],
|
118 |
outputs=output_audio
|
119 |
)
|
120 |
|
121 |
if __name__ == "__main__":
|
122 |
+
demo.launch()
|