Text-to-Speech
F5-TTS
Safetensors
Nepali
nepali
tts
voice-cloning
pruned
tiny-swar / load_tiny_swar.py
voidash's picture
Tiny Swar: 16-block Swar, 1.35x faster
728171b
Raw History Blame Contribute Delete
1.51 kB
"""Load Tiny Swar (16-block F5-TTS DiT) with the stock f5-tts package.
from load_tiny_swar import load
tts = load("model.safetensors", "vocab.txt", device="cuda")
tts.infer(ref_file="ref.wav", ref_text="...", gen_text="नमस्ते, तपाईंलाई कस्तो छ?",
nfe_step=16, cfg_strength=2.0, seed=0, file_wave="out.wav")
f5-tts builds F5TTS_Base with 22 blocks from its YAML config. This helper sets depth to 16 for that one
config load, then checks that the built model really has 16 blocks.
"""
import json
import types
from pathlib import Path
import f5_tts.api as api
DEPTH = 16
def load(ckpt="model.safetensors", vocab="vocab.txt", device="cuda", vocoder_local_path=None, fp32=True):
cfg_path = Path(ckpt).with_name("config.json")
depth = json.loads(cfg_path.read_text())["arch"]["depth"] if cfg_path.exists() else DEPTH
real = api.OmegaConf
def _load(path):
cfg = real.load(path)
cfg.model.arch.depth = depth
return cfg
api.OmegaConf = types.SimpleNamespace(load=_load)
try:
tts = api.F5TTS(model="F5TTS_Base", ckpt_file=str(ckpt), vocab_file=str(vocab), device=device,
vocoder_local_path=vocoder_local_path)
finally:
api.OmegaConf = real
built = len(tts.ema_model.transformer.transformer_blocks)
if built != depth:
raise RuntimeError(f"built {built} blocks, expected {depth}")
if fp32:
tts.ema_model.float()
return tts