Spaces:
Runtime error
Runtime error
Upload app.py with huggingface_hub
Browse files
app.py
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
```python
|
2 |
+
import gradio as gr
|
3 |
+
import os
|
4 |
+
from gtts import gTTS
|
5 |
+
import tempfile
|
6 |
+
|
7 |
+
def text_to_speech(text, lang):
|
8 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as fp:
|
9 |
+
tts = gTTS(text=text, lang=lang)
|
10 |
+
tts.save(fp.name)
|
11 |
+
return fp.name
|
12 |
+
|
13 |
+
supported_languages = {
|
14 |
+
"English": "en",
|
15 |
+
"Korean": "ko",
|
16 |
+
"Japanese": "ja",
|
17 |
+
"Chinese": "zh-cn",
|
18 |
+
"Spanish": "es",
|
19 |
+
"French": "fr",
|
20 |
+
"German": "de"
|
21 |
+
}
|
22 |
+
|
23 |
+
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
24 |
+
with gr.Row():
|
25 |
+
with gr.Column():
|
26 |
+
text_input = gr.Textbox(
|
27 |
+
label="Input Text",
|
28 |
+
placeholder="Enter text to convert to speech...",
|
29 |
+
lines=5
|
30 |
+
)
|
31 |
+
lang_dropdown = gr.Dropdown(
|
32 |
+
choices=list(supported_languages.keys()),
|
33 |
+
value="English",
|
34 |
+
label="Select Language"
|
35 |
+
)
|
36 |
+
btn = gr.Button("Convert to Speech")
|
37 |
+
|
38 |
+
with gr.Column():
|
39 |
+
audio_output = gr.Audio(label="Generated Speech")
|
40 |
+
|
41 |
+
btn.click(
|
42 |
+
fn=lambda text, lang: text_to_speech(text, supported_languages[lang]),
|
43 |
+
inputs=[text_input, lang_dropdown],
|
44 |
+
outputs=audio_output
|
45 |
+
)
|
46 |
+
|
47 |
+
if __name__ == "__main__":
|
48 |
+
demo.launch()
|
49 |
+
```
|