Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,52 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
|
|
|
|
| 3 |
def greet(name):
|
| 4 |
return "Hello " + name + "!!"
|
| 5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
iface = gr.Interface(fn=greet, inputs="text", outputs="text")
|
| 7 |
-
iface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
+
|
| 4 |
def greet(name):
|
| 5 |
return "Hello " + name + "!!"
|
| 6 |
|
| 7 |
+
|
| 8 |
+
language_dict = {
|
| 9 |
+
"English-Jenny (Female)": "en-US-JennyNeural",
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
async def text_to_speech_edge(text, language_code, rate, volume, pitch):
|
| 14 |
+
voice = language_dict.get(language_code, "default_voice")
|
| 15 |
+
|
| 16 |
+
rates = "+" + str(rate) + "%" if rate >= 0 else str(rate) + "%"
|
| 17 |
+
volumes = "+" + str(volume) + "%" if volume >= 0 else str(volume) + "%"
|
| 18 |
+
pitchs = "+" + str(pitch) + "Hz" if pitch >= 0 else str(pitch) + "Hz"
|
| 19 |
+
|
| 20 |
+
communicate = edge_tts.Communicate(
|
| 21 |
+
text, voice, rate=rates, volume=volumes, pitch=pitchs, proxy=None
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp_file:
|
| 25 |
+
tmp_path = tmp_file.name
|
| 26 |
+
await communicate.save(tmp_path)
|
| 27 |
+
return f"Speech synthesis completed for: {text}", tmp_path
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
input_text = gr.Textbox(lines=5, label="Input Text")
|
| 31 |
+
output_text = gr.Textbox(label="Output Text")
|
| 32 |
+
output_audio = gr.Audio(type="filepath", label="Exported Audio")
|
| 33 |
+
language = gr.Dropdown(
|
| 34 |
+
choices=list(language_dict.keys()), label="Choose the Voice Model"
|
| 35 |
+
)
|
| 36 |
+
rate = gr.Slider(
|
| 37 |
+
-100, 100, step=1, value=0, label="Rate", info="Rate", interactive=True
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
volume = gr.Slider(
|
| 41 |
+
-100, 100, step=1, value=0, label="Volume", info="Volume", interactive=True
|
| 42 |
+
)
|
| 43 |
+
|
| 44 |
+
pitch = gr.Slider(
|
| 45 |
+
-100, 100, step=1, value=0, label="Pitch", info="Pitch", interactive=True
|
| 46 |
+
)
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
|
| 51 |
iface = gr.Interface(fn=greet, inputs="text", outputs="text")
|
| 52 |
+
iface.launch()
|