Add naturalness and phonetic testing script
This commit is contained in:
1 parent
ce49f9fa91
commit
b8f6283dbc
1 file changed
+107
@@ -0,0 +1,107 @@
|
||||
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 = "cpu"
|
||||
print(f"[Init] Running high-quality naturalness test on {device}...")
|
||||
|
||||
VOCAB_PATH = r"C:\GitHub\VocoLoom\models\F5-TTS-German\vocab.txt"
|
||||
CKPT_PATH = r"C:\GitHub\VocoLoom\ckpts\Juergen_Seiferth\model_800.pt"
|
||||
|
||||
# Use lively/energetic Platz reference instead of tired/calm one
|
||||
REF_AUDIO = r"C:\GitHub\VocoLoom\ref_juergen_platz.wav"
|
||||
REF_TEXT = "Fertig Ballett oder Fertig Öl oder was? Was?"
|
||||
|
||||
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,
|
||||
)
|
||||
|
||||
print(f"Building CFM model and loading {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="cpu", 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()
|
||||
|
||||
print("Loading Vocos...")
|
||||
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)
|
||||
|
||||
# Test 1: Original text with higher NFE (48) and relaxed CFG (1.5)
|
||||
text_orig = "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!"
|
||||
out_orig = r"C:\GitHub\VocoLoom\juergen_f5_800_natural.wav"
|
||||
print(f"\n[Test 1] Generating: {out_orig} (cfg=1.5, nfe=48)...")
|
||||
audio1, sr1, _ = infer_process(
|
||||
ref_audio_proc,
|
||||
ref_text_proc,
|
||||
text_orig,
|
||||
model,
|
||||
vocoder,
|
||||
mel_spec_type="vocos",
|
||||
nfe_step=48,
|
||||
cfg_strength=1.5,
|
||||
target_rms=0.1,
|
||||
speed=1.0,
|
||||
device=device,
|
||||
)
|
||||
sf.write(out_orig, audio1, sr1)
|
||||
print(f"[Done] Saved: {out_orig}")
|
||||
|
||||
# Test 2: Phonetic German spelling ('onlein') with natural phrasing
|
||||
text_ph = "Frag mal, ob du die Fotos vom Tobias bekommst. Wir haben keine gemacht. Aber nicht in die Gruppen rein senden! Der Kenny stellt das bloß wieder onlein!"
|
||||
out_ph = r"C:\GitHub\VocoLoom\juergen_f5_800_phonetic.wav"
|
||||
print(f"\n[Test 2] Generating: {out_ph} (phonetic 'onlein', cfg=1.5, nfe=48)...")
|
||||
audio2, sr2, _ = infer_process(
|
||||
ref_audio_proc,
|
||||
ref_text_proc,
|
||||
text_ph,
|
||||
model,
|
||||
vocoder,
|
||||
mel_spec_type="vocos",
|
||||
nfe_step=48,
|
||||
cfg_strength=1.5,
|
||||
target_rms=0.1,
|
||||
speed=1.0,
|
||||
device=device,
|
||||
)
|
||||
sf.write(out_ph, audio2, sr2)
|
||||
print(f"[Done] Saved: {out_ph}")
|
||||
print("\n[ALL FINISHED SUCCESSFULLY]")
|
||||
Reference in new issue
Block a user