Add script testing clear pronunciation variants of kriegst

This commit is contained in:
Jannik committed 2026-11-08 10:04:18 +01:00
1 parent 8da48317e4
commit 68f9d89669
1 file changed
+102
+102
View File
@@ -0,0 +1,102 @@
import os
import sys
import torch
import numpy as np
import soundfile as sf
BASE_DIR = r"C:\GitHub\VocoLoom"
os.chdir(r"C:\GitHub\VocoLoom\Applio")
sys.path.insert(0, r"C:\GitHub\VocoLoom\Applio")
from core import run_infer_script
pth_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"
from f5_tts.infer.utils_infer import (
load_vocoder,
infer_process,
preprocess_ref_audio_text,
)
from f5_tts.model import CFM, DiT
from f5_tts.model.utils import get_tokenizer
device = "cuda" if torch.cuda.is_available() else "cpu"
VOCAB_PATH = os.path.join(BASE_DIR, "models", "F5-TTS-German", "vocab.txt")
CKPT_PATH = os.path.join(BASE_DIR, "ckpts", "Juergen_Seiferth", "model_200.pt")
REF_AUDIO = os.path.join(BASE_DIR, "cleaned_dataset", "snippet_10_00-06-13-10_to_00-06-23-10_clean.wav")
REF_TEXT = "Ich bin immer zufrieden. Ich muss das mal so sagen. Was nicht ganz läuft so wie ich das will, das wird so gemacht, damit das läuft. Zum Endeffekt ist passend."
vocab_char_map, vocab_size = get_tokenizer(VOCAB_PATH, "custom")
mel_spec_kwargs = dict(n_fft=1024, hop_length=256, win_length=1024, n_mel_channels=100, target_sample_rate=24000, mel_spec_type="vocos")
model_cfg = dict(dim=1024, depth=22, heads=16, ff_mult=2, text_dim=512, text_mask_padding=False, conv_layers=4, pe_attn_head=1)
vocoder = load_vocoder(vocoder_name="vocos", is_local=False, device=device)
ref_audio_proc, ref_text_proc = preprocess_ref_audio_text(REF_AUDIO, REF_TEXT)
model = CFM(
transformer=DiT(**model_cfg, text_num_embeds=vocab_size, mel_dim=100),
mel_spec_kwargs=mel_spec_kwargs,
vocab_char_map=vocab_char_map,
)
checkpoint = torch.load(CKPT_PATH, map_location=device, weights_only=True)
ema_state = {k.replace("ema_model.", ""): v for k, v in checkpoint["ema_model_state_dict"].items() if k not in ["initted", "step"]}
for key in ["mel_spec.mel_stft.mel_scale.fb", "mel_spec.mel_stft.spectrogram.window"]:
if key in ema_state:
del ema_state[key]
model.load_state_dict(ema_state)
model = model.to(device).eval()
part2 = "Aber nicht in die Gruppen rein senden! Der Kenny stellt's bloß wieder online."
p2_audio, _, _ = infer_process(ref_audio_proc, ref_text_proc, part2, model, vocoder, mel_spec_type="vocos", nfe_step=64, cfg_strength=1.8, target_rms=0.1, speed=1.0, device=device)
silence_250ms = np.zeros(int(24000 * 0.25), dtype=np.float32)
test_variants = [
# 1. kriegst with exclamation mark and comma
("kriegst_klar", "Frag mal, ob du die Fotos vom Tobias kriegst! Wir haben keine gemacht."),
# 2. krichst (Ruhrpott colloquial phonetic)
("krichst", "Frag mal, ob du die Fotos vom Tobias krichst. Wir haben keine gemacht."),
# 3. kriegst without comma
("kriegst_glatt", "Frag mal ob du die Fotos vom Tobias kriegst. Wir haben keine gemacht."),
]
for tag, p1_text in test_variants:
print(f"\nGenerating variant: {tag} ({p1_text})...")
p1_audio, sr, _ = infer_process(ref_audio_proc, ref_text_proc, p1_text, model, vocoder, mel_spec_type="vocos", nfe_step=64, cfg_strength=1.8, target_rms=0.1, speed=1.0, device=device)
full_audio = np.concatenate([p1_audio, silence_250ms, p2_audio])
f5_file = os.path.join(BASE_DIR, f"juergen_{tag}_f5.wav")
rvc_file = os.path.join(BASE_DIR, f"juergen_{tag}_idx70.wav")
sf.write(f5_file, full_audio, sr)
print(f"Saved pure F5: {f5_file}")
# Also create the 0.70 index version (user's favorite index)
run_infer_script(
pitch=0,
index_rate=0.70,
volume_envelope=1.0,
protect=0.33,
f0_method="rmvpe",
input_path=f5_file,
output_path=rvc_file,
pth_path=pth_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
)
print(f"Saved RVC 70%: {rvc_file}")
print("\n[ALL FINISHED SUCCESSFULLY]")