129 lines
4.1 KiB
Python
129 lines
4.1 KiB
Python
import os
|
|
import sys
|
|
import torch
|
|
import soundfile as sf
|
|
|
|
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"
|
|
print(f"Using device: {device}")
|
|
|
|
BASE_DIR = r"C:\GitHub\VocoLoom"
|
|
VOCAB_PATH = os.path.join(BASE_DIR, "models", "F5-TTS-German", "vocab.txt")
|
|
CKPT_DIR = os.path.join(BASE_DIR, "ckpts", "Juergen_Seiferth")
|
|
|
|
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."
|
|
|
|
TARGET_TEXT = "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!"
|
|
|
|
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)
|
|
|
|
def generate(ckpt_path, out_filename, nfe=64, cfg=1.8):
|
|
print(f"\n--- Testing Checkpoint: {os.path.basename(ckpt_path)} ---")
|
|
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)
|
|
if "ema_model_state_dict" in checkpoint:
|
|
ema_state = {
|
|
k.replace("ema_model.", ""): v
|
|
for k, v in checkpoint["ema_model_state_dict"].items()
|
|
if k not in ["initted", "step"]
|
|
}
|
|
else:
|
|
ema_state = checkpoint
|
|
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()
|
|
|
|
out_path = os.path.join(BASE_DIR, out_filename)
|
|
audio, sr, _ = infer_process(
|
|
ref_audio_proc,
|
|
ref_text_proc,
|
|
TARGET_TEXT,
|
|
model,
|
|
vocoder,
|
|
mel_spec_type="vocos",
|
|
nfe_step=nfe,
|
|
cfg_strength=cfg,
|
|
target_rms=0.1,
|
|
speed=1.0,
|
|
device=device,
|
|
)
|
|
sf.write(out_path, audio, sr)
|
|
print(f"[Done] Generated: {out_path}")
|
|
del model
|
|
torch.cuda.empty_cache()
|
|
return out_path
|
|
|
|
# Generate step 100 and step 300
|
|
generate(os.path.join(CKPT_DIR, "model_100.pt"), "juergen_chef_step100.wav")
|
|
generate(os.path.join(CKPT_DIR, "model_300.pt"), "juergen_chef_step300.wav")
|
|
|
|
# Also generate a subtle RVC version of step200
|
|
print("\nApplying subtle RVC (index 0.25) to step200...")
|
|
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.25,
|
|
volume_envelope=1.0,
|
|
protect=0.40,
|
|
f0_method="rmvpe",
|
|
input_path=os.path.join(BASE_DIR, "juergen_chef_step200.wav"),
|
|
output_path=os.path.join(BASE_DIR, "juergen_chef_step200_rvc_subtle.wav"),
|
|
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",
|
|
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("[Done] All sweetspot tests finished!")
|