"""Measure real-time factor (RTF) for the shipped model. python benchmark/rtf.py --model . [--device cpu|cuda] RTF = compute seconds / audio seconds. Lower is better; 0.01 means 100x faster than real time. Warm-up runs are excluded. """ import argparse import json import sys import time from pathlib import Path import torch sys.path.insert(0, str(Path(__file__).resolve().parents[1])) from microtts import MicroTTS # noqa: E402 SENTS = [ "The morning light came through the curtains and touched the wooden floor.", "I found an old map in the drawer, folded twice and soft at the edges.", "Please remind me to call the plumber before the end of the week.", "Numbers like 42 and 2026 should be spoken clearly.", "The train leaves at half past seven from the north platform.", "She wore a green coat and carried a small brown bag.", "We can meet by the river if the weather stays clear.", "He wrote the address on the back of an envelope.", ] def main(): ap = argparse.ArgumentParser() ap.add_argument("--model", default=".") ap.add_argument("--device", default="cpu") a = ap.parse_args() tts = MicroTTS.load(a.model, device=a.device) for s in SENTS[:2]: # warm-up tts.synthesize(s) if a.device == "cuda": torch.cuda.synchronize() total_audio = 0.0 t0 = time.time() for s in SENTS: wav = tts.synthesize(s) total_audio += len(wav) / 24000.0 dt = time.time() - t0 print(f"device={a.device} audio={total_audio:.2f}s compute={dt:.2f}s " f"RTF={dt/total_audio:.4f} ({total_audio/dt:.1f}x realtime)") print(json.dumps({"device": a.device, "rtf": round(dt / total_audio, 4), "realtime_factor": round(total_audio / dt, 1)})) if __name__ == "__main__": main()