189 lines
7.6 KiB
Python
189 lines
7.6 KiB
Python
import os
|
||
import sys
|
||
import subprocess
|
||
import gradio as gr
|
||
|
||
BASE_DIR = r"C:\GitHub\VocoLoom"
|
||
F5_CLI = r"C:\GitHub\VocoLoom\.venv\Scripts\f5-tts_infer-cli.exe"
|
||
GERMAN_CKPT = r"C:\GitHub\VocoLoom\models\F5-TTS-German\model_420000.safetensors"
|
||
GERMAN_VOCAB = r"C:\GitHub\VocoLoom\models\F5-TTS-German\vocab.txt"
|
||
|
||
REF_LKW = r"C:\GitHub\VocoLoom\real_juergen_short.wav"
|
||
REF_TEXT_LKW = "Soll mich aufregen? Eigentlich gar nicht. Lässt mich von der Sache her ein bisschen alles."
|
||
|
||
REF_PLATZ = r"C:\GitHub\VocoLoom\ref_juergen_platz.wav"
|
||
REF_TEXT_PLATZ = "Fertig Ballett oder Fertig Öl oder was? Was?"
|
||
|
||
MODEL_PATH = r"C:\GitHub\VocoLoom\Applio\logs\Juergen_Seiferth\Juergen_Seiferth_300e_7800s.pth"
|
||
INDEX_PATH = r"C:\GitHub\VocoLoom\Applio\logs\Juergen_Seiferth\Juergen_Seiferth.index"
|
||
|
||
def tts_generate(text, mood, use_rvc):
|
||
if not text.strip():
|
||
return None, "Bitte gib einen Text ein."
|
||
|
||
ref_audio = REF_PLATZ if mood == "platz" else REF_LKW
|
||
ref_text = REF_TEXT_PLATZ if mood == "platz" else REF_TEXT_LKW
|
||
|
||
temp_text_file = os.path.join(BASE_DIR, "web_gen_text.txt")
|
||
with open(temp_text_file, "w", encoding="utf-8") as f:
|
||
f.write(text.strip())
|
||
|
||
f5_out = os.path.join(BASE_DIR, "web_f5_output.wav")
|
||
final_out = os.path.join(BASE_DIR, "web_juergen_speech.wav")
|
||
|
||
cmd = [
|
||
F5_CLI,
|
||
"-m", "F5TTS_Base",
|
||
"-p", GERMAN_CKPT,
|
||
"-v", GERMAN_VOCAB,
|
||
"-r", ref_audio,
|
||
"-s", ref_text,
|
||
"-f", temp_text_file,
|
||
"-o", BASE_DIR,
|
||
"-w", "web_f5_output.wav",
|
||
"--device", "cuda",
|
||
"--remove_silence"
|
||
]
|
||
subprocess.run(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||
|
||
if not os.path.exists(f5_out):
|
||
return None, "Fehler bei der F5-TTS Synthese."
|
||
|
||
if use_rvc:
|
||
os.chdir(r"C:\GitHub\VocoLoom\Applio")
|
||
sys.path.insert(0, r"C:\GitHub\VocoLoom\Applio")
|
||
from core import run_infer_script
|
||
|
||
run_infer_script(
|
||
pitch=0,
|
||
index_rate=0.40,
|
||
volume_envelope=1.0,
|
||
protect=0.33,
|
||
f0_method="rmvpe",
|
||
input_path=f5_out,
|
||
output_path=final_out,
|
||
pth_path=MODEL_PATH,
|
||
index_path=INDEX_PATH,
|
||
f0_autotune=False,
|
||
f0_autotune_strength=1.0,
|
||
proposed_pitch=False,
|
||
proposed_pitch_threshold=155.0,
|
||
export_format="WAV",
|
||
embedder_model="contentvec",
|
||
embedder_model_custom=None,
|
||
formant_shifting=False,
|
||
formant_qfrency=1.0,
|
||
formant_timbre=1.0,
|
||
sid=0,
|
||
inference_engine=None,
|
||
onnx_precision="auto",
|
||
cleanup_mode="off",
|
||
cleanup_strength=12
|
||
)
|
||
else:
|
||
import shutil
|
||
shutil.copyfile(f5_out, final_out)
|
||
|
||
status_msg = f"Erfolgreich generiert ({'🔥 Impulsiv / Auf dem Platz' if mood == 'platz' else '☕ Ruhig / LKW'}) mit {'RVC 300e Veredelung' if use_rvc else 'Pure F5-TTS'}."
|
||
return final_out, status_msg
|
||
|
||
def vc_convert(audio_path):
|
||
if not audio_path:
|
||
return None, "Bitte nimm Audio auf oder lade eine Datei hoch."
|
||
|
||
os.chdir(r"C:\GitHub\VocoLoom\Applio")
|
||
sys.path.insert(0, r"C:\GitHub\VocoLoom\Applio")
|
||
from core import run_infer_script
|
||
|
||
out_rvc = os.path.join(BASE_DIR, "web_vc_juergen.wav")
|
||
run_infer_script(
|
||
pitch=0,
|
||
index_rate=0.75,
|
||
volume_envelope=1.0,
|
||
protect=0.33,
|
||
f0_method="rmvpe",
|
||
input_path=audio_path,
|
||
output_path=out_rvc,
|
||
pth_path=MODEL_PATH,
|
||
index_path=INDEX_PATH,
|
||
f0_autotune=False,
|
||
f0_autotune_strength=1.0,
|
||
proposed_pitch=False,
|
||
proposed_pitch_threshold=155.0,
|
||
export_format="WAV",
|
||
embedder_model="contentvec",
|
||
embedder_model_custom=None,
|
||
formant_shifting=False,
|
||
formant_qfrency=1.0,
|
||
formant_timbre=1.0,
|
||
sid=0,
|
||
inference_engine=None,
|
||
onnx_precision="auto",
|
||
cleanup_mode="off",
|
||
cleanup_strength=12,
|
||
)
|
||
return out_rvc, "Stimme erfolgreich 1:1 in Jürgen Seiferth umgewandelt!"
|
||
|
||
with gr.Blocks(title="VocoLoom - Jürgen Seiferth Voice Clone") as demo:
|
||
gr.Markdown("# 🎡 VocoLoom: Jürgen Seiferth (1995 Original)")
|
||
gr.Markdown("*Breakdance-Schausteller-Stimme geklont aus MDR 'Die Welt ist unser Feld' (F5-TTS German + 300 Epochen RVC)*")
|
||
|
||
with gr.Tab("✍️ Text-to-Speech (Schreiben -> Jürgen spricht)"):
|
||
with gr.Row():
|
||
with gr.Column(scale=2):
|
||
text_input = gr.Textbox(
|
||
label="Text eingeben",
|
||
placeholder="Schreib hier, was Jürgen sagen soll...",
|
||
lines=3,
|
||
value="Frag mal ob du die Fotos vom Tobias bekommst. Wir haben keine gemacht. Aber nicht in die Gruppen rein senden! Der Kenny stellt es bloß wieder online!"
|
||
)
|
||
with gr.Row():
|
||
mood_radio = gr.Radio(
|
||
choices=[("🔥 Impulsiv / Auf dem Platz", "platz"), ("☕ Ruhig / LKW-Fahrerkabine", "lkw")],
|
||
value="platz",
|
||
label="Stimmung / Sprechweise"
|
||
)
|
||
rvc_toggle = gr.Checkbox(label="300-Epochen RVC Veredelung (Empfohlen)", value=True)
|
||
|
||
generate_btn = gr.Button("🎙️ Jürgen sprechen lassen", variant="primary")
|
||
|
||
gr.Examples(
|
||
examples=[
|
||
["Frag mal ob du die Fotos vom Tobias bekommst. Wir haben keine gemacht. Aber nicht in die Gruppen rein senden! Der Kenny stellt es bloß wieder online!", "platz", True],
|
||
["Frag ma, ob de die Fotos vom Tobias kriegst! Wir ham keene gemacht. Aber nich in die Gruppen neistellen... der Kenny stellt's bloß wieder online!", "platz", True],
|
||
["Fertig Ballett oder was?! Mensch, da guckt man nicht zu, da packt man an!", "platz", True],
|
||
["Soll mich aufregen? Eigentlich gar nicht. Von der Sache her lässt mich alles eiskalt. Hauptsache angekommen!", "lkw", True],
|
||
["Pass mal auf! Was nicht ganz läuft so wie ich das will, das wird so gemacht, damit das läuft!", "platz", True],
|
||
],
|
||
inputs=[text_input, mood_radio, rvc_toggle]
|
||
)
|
||
|
||
with gr.Column(scale=1):
|
||
audio_output = gr.Audio(label="Jürgen spricht:", type="filepath")
|
||
status_box = gr.Textbox(label="Status", interactive=False)
|
||
|
||
generate_btn.click(
|
||
tts_generate,
|
||
inputs=[text_input, mood_radio, rvc_toggle],
|
||
outputs=[audio_output, status_box]
|
||
)
|
||
|
||
with gr.Tab("🎤 Voice Changer (Mikrofon / Audio -> Jürgen)"):
|
||
gr.Markdown("Sprich selbst ins Mikrofon (mit Dialekt & Betonung) oder lade Audio hoch – das Modell wandelt deine Stimme 1:1 in Jürgen Seiferth um!")
|
||
with gr.Row():
|
||
with gr.Column():
|
||
audio_input = gr.Audio(label="Deine Stimme aufnehmen oder hochladen", type="filepath")
|
||
convert_btn = gr.Button("🔄 In Jürgen umwandeln", variant="primary")
|
||
with gr.Column():
|
||
vc_output = gr.Audio(label="Ergebnis in Jürgens Stimme:", type="filepath")
|
||
vc_status = gr.Textbox(label="Status", interactive=False)
|
||
|
||
convert_btn.click(
|
||
vc_convert,
|
||
inputs=[audio_input],
|
||
outputs=[vc_output, vc_status]
|
||
)
|
||
|
||
if __name__ == "__main__":
|
||
demo.launch(server_name="127.0.0.1", server_port=7860, inbrowser=False, allowed_paths=[BASE_DIR])
|