Spaces:
Sleeping
Sleeping
tangjicheng
commited on
Commit
•
8a98fc0
1
Parent(s):
f77ac40
new file: app.py
Browse filesnew file: requirements.txt
- app.py +27 -0
- requirements.txt +1 -0
app.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from gtts import gTTS
|
3 |
+
import os
|
4 |
+
|
5 |
+
os.makedirs("temp", exist_ok=True)
|
6 |
+
|
7 |
+
input_text = gr.inputs.Textbox(label="input_text")
|
8 |
+
|
9 |
+
output_audio = gr.outputs.Audio(type="filepath", label="output_audio")
|
10 |
+
|
11 |
+
def text_to_speech(text, speed=1.0, lang="en"):
|
12 |
+
tts = gTTS(text, lang=lang)
|
13 |
+
tts.speed = speed
|
14 |
+
audio_file = os.path.join("temp", "output.mp3")
|
15 |
+
tts.save(audio_file)
|
16 |
+
return audio_file
|
17 |
+
|
18 |
+
iface = gr.Interface(
|
19 |
+
fn=text_to_speech,
|
20 |
+
inputs=[input_text, gr.inputs.Slider(minimum=0.5, maximum=2.0, default=1.0, step=0.1, label="speed"), gr.inputs.Dropdown([
|
21 |
+
"en", "es", "fr", "zh"], label="language", default="zh")],
|
22 |
+
outputs=output_audio,
|
23 |
+
title="TextToSpeech",
|
24 |
+
theme="default"
|
25 |
+
)
|
26 |
+
|
27 |
+
iface.launch()
|
requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
gtts
|