"""web graph vs release graph on the 80 bench lines (kenzie): same length, waveform correlation, log-spectrogram distance.""" import json, sys, numpy as np sys.path.insert(0, "../_bench"); from bench_core import load import onnxruntime as ort S = sys.argv[1] if len(sys.argv) > 1 else "nano"; M = f"../../models/kale-tts-1-{S}"; lines = json.load(open("../_bench/lines80.json")) _, a, _ = load(M, threads=4) import shutil, tempfile, os d = tempfile.mkdtemp(); [os.symlink(os.path.abspath(f"{M}/{f}"), f"{d}/{f}") for f in os.listdir(M) if f != "model.onnx"] os.symlink(os.path.abspath(f"web-graph/kale-tts-1-{S}.web.onnx"), f"{d}/model.onnx"); _, b, _ = load(d, threads=4) def spec(x): x = x[: len(x) // 480 * 480].reshape(-1, 480) * np.hanning(480); return np.log(np.abs(np.fft.rfft(x)) + 1e-5) cor, sd, mx, same = [], [], [], 0 for l in lines: for ids in l: x, y = a(ids)[0], b(ids)[0]; same += len(x) == len(y); n = min(len(x), len(y)); x, y = x[:n], y[:n] cor.append(np.corrcoef(x, y)[0, 1]); mx.append(np.abs(x - y).max()); sd.append(np.sqrt(np.mean((spec(x) - spec(y)) ** 2))) print(json.dumps(dict(model=S, sentences=len(cor), same_length=same, wave_corr_min=round(float(min(cor)), 5), wave_corr_median=round(float(np.median(cor)), 6), max_abs_diff=round(float(max(mx)), 5), logspec_rmse_median_db=round(float(np.median(sd)) * 8.686, 3), logspec_rmse_max_db=round(float(max(sd)) * 8.686, 3))))