Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from TTS.api import TTS
|
3 |
+
import tempfile
|
4 |
+
import os
|
5 |
+
|
6 |
+
# Modell laden
|
7 |
+
tts = TTS(model_name="tts_models/multilingual/multi-dataset/xtts_v2", gpu=False)
|
8 |
+
|
9 |
+
def generate_audio(text, speaker_wav, language):
|
10 |
+
# Temporäre Datei erstellen
|
11 |
+
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as fp:
|
12 |
+
output_path = fp.name
|
13 |
+
|
14 |
+
# TTS-Generierung
|
15 |
+
tts.tts_to_file(
|
16 |
+
text=text,
|
17 |
+
speaker_wav=speaker_wav,
|
18 |
+
language=language,
|
19 |
+
file_path=output_path
|
20 |
+
)
|
21 |
+
|
22 |
+
return output_path
|
23 |
+
|
24 |
+
# Gradio-UI
|
25 |
+
with gr.Blocks() as demo:
|
26 |
+
gr.Markdown("# 🗣️ XTTS Text-to-Speech")
|
27 |
+
gr.Markdown("Coqui XTTS multilingual TTS Demo")
|
28 |
+
|
29 |
+
with gr.Row():
|
30 |
+
with gr.Column():
|
31 |
+
text_input = gr.Textbox(label="Eingabetext", placeholder="Text hier eingeben...")
|
32 |
+
speaker_input = gr.Audio(label="Referenzstimme (max 10s)", sources=["upload"], type="filepath")
|
33 |
+
language = gr.Dropdown(
|
34 |
+
label="Sprache",
|
35 |
+
choices=["en", "de", "es", "fr", "it", "pt", "pl"],
|
36 |
+
value="en"
|
37 |
+
)
|
38 |
+
btn = gr.Button("Generieren")
|
39 |
+
|
40 |
+
with gr.Column():
|
41 |
+
audio_output = gr.Audio(label="Generierte Sprache", autoplay=True)
|
42 |
+
|
43 |
+
btn.click(
|
44 |
+
fn=generate_audio,
|
45 |
+
inputs=[text_input, speaker_input, language],
|
46 |
+
outputs=audio_output
|
47 |
+
)
|
48 |
+
|
49 |
+
if __name__ == "__main__":
|
50 |
+
demo.launch()
|