Files

134 lines
6.2 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import os
import gradio as gr
from vocoloom.voice_manager import VoiceManager
def create_ui(manager: VoiceManager) -> gr.Blocks:
voices = manager.list_voices()
voice_choices = [(f"{v.name} ({v.dialect or v.language})", v.id) for v in voices]
default_voice_id = voices[0].id if voices else ""
default_voice = manager.get_voice(default_voice_id) if default_voice_id else None
custom_css = """
body { font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, Roboto, sans-serif; }
.vocoloom-container { max-width: 1000px !important; margin: auto; }
.voice-badge { display: inline-block; padding: 2px 8px; border-radius: 12px; background: #e0e7ff; color: #3730a3; font-size: 0.8em; margin-right: 4px; font-weight: 600; }
.voice-card { background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 12px; padding: 16px; margin-bottom: 12px; }
"""
with gr.Blocks(title="VocoLoom — Voice Platform") as demo:
gr.Markdown("# 🎡 VocoLoom — Multi-Voice Studio", elem_id="header-title")
gr.Markdown("Wähle eine gehostete KI-Stimme aus oder füge neue Stimmen im `voices/`-Ordner hinzu.")
with gr.Row():
# Left column: Voice selection & parameters
with gr.Column(scale=3):
with gr.Group(elem_classes=["voice-card"]):
voice_dropdown = gr.Dropdown(
choices=voice_choices,
value=default_voice_id,
label="🎙️ Verfügbare Stimmen",
interactive=True
)
voice_desc_box = gr.Markdown(
value=f"**{default_voice.name}** — *{default_voice.subtitle}*\n\n{default_voice.description}\n\n" +
" ".join([f"<span class='voice-badge'>{t}</span>" for t in default_voice.tags]) if default_voice else ""
)
text_input = gr.Textbox(
label="Text eingeben",
lines=4,
value=default_voice.sample_sentences[0] if (default_voice and default_voice.sample_sentences) else "",
placeholder="Tippe hier deinen beliebigen Text ein..."
)
with gr.Row():
speed_slider = gr.Slider(
minimum=0.6,
maximum=1.4,
value=default_voice.default_speed if default_voice else 1.0,
step=0.05,
label="Sprechgeschwindigkeit"
)
use_rvc_check = gr.Checkbox(
label="Zusätzliche RVC-Veredelung",
value=False,
visible=bool(default_voice and default_voice.rvc_support.get("supported"))
)
generate_btn = gr.Button("🎤 Sprache synthetisieren", variant="primary", size="lg")
# Sample sentences
gr.Markdown("#### 💡 Typische Sprüche & Zitate:")
sample_buttons = []
with gr.Column():
samples = default_voice.sample_sentences if default_voice else []
for s in samples[:4]:
btn = gr.Button(s, size="sm", variant="secondary")
btn.click(fn=lambda text=s: text, outputs=[text_input])
sample_buttons.append(btn)
# Right column: Output audio and stats
with gr.Column(scale=2):
audio_output = gr.Audio(label="Generierte Sprachausgabe", type="filepath")
status_box = gr.Textbox(label="Status", interactive=False)
with gr.Accordion("ℹ️ Wie füge ich weitere Stimmen hinzu?", open=False):
gr.Markdown(
"""
Jede Stimme in VocoLoom ist ein modularer Ordner im Verzeichnis `voices/<id>/`:
- `voice.json`: Metadaten, Prompts, Tags, Standardwerte
- `model.pt`: F5-TTS Fine-Tuned Checkpoint
- `reference.wav`: Saubere Referenz-Audiodatei
- `reference.txt`: Exaktes Transkript
- `avatar.png`: Bild für die Benutzeroberfläche
Sobald ein neuer Ordner in `voices/` abgelegt wird, erscheint die Stimme sofort auf der Plattform!
"""
)
# Dropdown change handler
def on_voice_change(selected_id):
v = manager.get_voice(selected_id)
if not v:
return "", "", 1.0, False, gr.update()
card_md = f"**{v.name}** — *{v.subtitle}*\n\n{v.description}\n\n" + " ".join([f"<span class='voice-badge'>{t}</span>" for t in v.tags])
sample_text = v.sample_sentences[0] if v.sample_sentences else ""
rvc_vis = bool(v.rvc_support.get("supported"))
return card_md, sample_text, v.default_speed, rvc_vis
voice_dropdown.change(
fn=on_voice_change,
inputs=[voice_dropdown],
outputs=[voice_desc_box, text_input, speed_slider, use_rvc_check]
)
# Generate handler
def generate(voice_id, text, speed, use_rvc):
if not text.strip():
return None, "Bitte gib einen Text ein."
try:
out_path = os.path.join(manager.root_dir, f"web_out_{voice_id}.wav")
audio, sr, msg = manager.synthesize(
voice_id=voice_id,
text=text,
speed=speed,
use_rvc=use_rvc,
output_path=out_path
)
return out_path, msg
except Exception as e:
return None, f"Fehler: {str(e)}"
generate_btn.click(
fn=generate,
inputs=[voice_dropdown, text_input, speed_slider, use_rvc_check],
outputs=[audio_output, status_box]
)
text_input.submit(
fn=generate,
inputs=[voice_dropdown, text_input, speed_slider, use_rvc_check],
outputs=[audio_output, status_box]
)
return demo, custom_css