"""Figures for paper_v2: parameter counts, the listening tests against Kokoro-82M, and the voice measures per decoder version. python paper_v2/figures/make.py (reads release_v2/results; writes paper_v2/figures/*.svg for the paper, *.png for the card) One colour scheme throughout: greys are Kokoro-82M, blues are this work's models, orange marks the published model.""" import json import os import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as plt from matplotlib.patches import Patch HERE = os.path.dirname(os.path.abspath(__file__)) RES = os.path.join(HERE, '..', '..', 'release_v2', 'results') INK, MUTED, RULE, BAND = '#1f2328', '#6b6b66', '#c9c8c2', '#f3f2ee' KOK_LIGHT, KOK_DARK = '#c3c7ce', '#7d8492' BLUE_DARK, BLUE_MID, BLUE_LIGHT = '#2b5c9e', '#5f8bc7', '#a7c0e3' SAME, RELEASE = '#e4e3de', '#d9822b' W = 6.3 # inches: the paper's text width plt.rcParams.update({ 'font.family': 'serif', 'font.serif': ['STIX Two Text', 'STIXGeneral'], 'mathtext.fontset': 'stix', 'font.size': 8.5, 'axes.edgecolor': RULE, 'axes.linewidth': 0.6, 'axes.labelcolor': INK, 'axes.labelsize': 8.5, 'xtick.color': MUTED, 'xtick.labelsize': 8, 'xtick.major.width': 0.6, 'xtick.major.size': 3, 'ytick.color': INK, 'ytick.labelsize': 8.5, 'axes.spines.top': False, 'axes.spines.right': False, 'axes.spines.left': False, 'axes.unicode_minus': True, 'legend.frameon': False, 'legend.fontsize': 8, 'svg.fonttype': 'none', 'savefig.dpi': 300, 'savefig.bbox': 'tight', 'savefig.pad_inches': 0.02}) def save(fig, name): for ext in ('svg', 'png'): fig.savefig(os.path.join(HERE, f'{name}.{ext}')) plt.close(fig) def bar_label(ax, x, y, s, dark): ax.text(x, y, s, ha='center', va='center', fontsize=8, color='white' if dark else INK) def params(): rows = [('Kokoro-82M', [('text side', 28.5, KOK_LIGHT), ('decoder', 53.3, KOK_DARK)], '81.8M'), ('nano-edge-tts', [('', 1.52, BLUE_DARK), ('', 0.96, BLUE_MID), ('', 0.79, BLUE_LIGHT)], '3.27M text side 1.52M · mapper 0.96M · renderer 0.79M')] fig, ax = plt.subplots(figsize=(W, 1.25)) for i, (_, parts, total) in enumerate(rows): x = 0 for label, v, c in parts: ax.barh(i, v, left=x, height=0.56, color=c, edgecolor='white', linewidth=0.8) if label: bar_label(ax, x + v / 2, i, f'{label} {v:g}M', c == KOK_DARK) x += v head, _, tail = total.partition(' ') t = ax.text(x + 1.0, i, head, va='center', color=INK, fontsize=8.5) if tail: ax.annotate(tail, xy=(1, 0.5), xycoords=t, xytext=(7, 0), textcoords='offset points', va='center', color=MUTED, fontsize=8) ax.set_yticks(range(len(rows)), [r[0] for r in rows]); ax.invert_yaxis() ax.set_xlim(0, 90); ax.set_xticks(range(0, 81, 20)); ax.set_xlabel('learned parameters (millions)') ax.tick_params(axis='y', length=0, pad=6) ax.legend(handles=[Patch(color=KOK_LIGHT, label='Kokoro-82M\'s networks'), Patch(color=BLUE_MID, label='nano-edge-tts')], ncol=2, loc='lower right', bbox_to_anchor=(1.0, 0.98), handlelength=1.1, handleheight=0.8, columnspacing=1.6) save(fig, 'params') def count(path, nano='nano4M'): c = {'k': 0, 's': 0, 'n': 0} for t in json.load(open(path)): if t['choice'] == 'same': c['s'] += 1 else: c['n' if (t['a_sys'] if t['choice'] == 'A' else t['b_sys']) == nano else 'k'] += 1 return c def listening(): pages = [('decoder F4', count(os.path.join(RES, 'listening_F4_vs_kokoro.json'))), ('F4 + post-filter', count(os.path.join(RES, 'listening_F4sharp_vs_kokoro.json'))), ('G2 + post-filter', count(os.path.join(RES, 'listening_G2sharp_vs_kokoro.json')))] keys = (('k', KOK_DARK, 'Kokoro-82M preferred', True), ('s', SAME, 'heard as the same', False), ('n', BLUE_DARK, 'nano-edge-tts preferred', True)) fig, ax = plt.subplots(figsize=(W, 1.55)) for i, (_, c) in enumerate(pages): x = 0 for key, col, _, dark in keys: ax.barh(i, c[key], left=x, height=0.56, color=col, edgecolor='white', linewidth=0.8) if c[key]: bar_label(ax, x + c[key] / 2, i, str(c[key]), dark) x += c[key] ax.set_yticks(range(len(pages)), [p[0] for p in pages]); ax.invert_yaxis() ax.set_xlim(0, 24); ax.set_xticks(range(0, 25, 4)); ax.set_xlabel('blind A/B trials (20 clips + 4 hidden repeats)') ax.tick_params(axis='y', length=0, pad=6) ax.legend(handles=[Patch(facecolor=col, edgecolor=RULE if col == SAME else col, linewidth=0.5, label=lab) for _, col, lab, _ in keys], ncol=3, loc='lower right', bbox_to_anchor=(1.0, 0.98), handlelength=1.1, handleheight=0.8, columnspacing=1.6) save(fig, 'listening') def offsets(): stats = [('fcontrast_4000-8000', 'crispness 4–8 kHz'), ('fcontrast_2000-4000', 'crispness 2–4 kHz'), ('breath_top_4-6k', 'breath 4–6 kHz'), ('breath_all_3-4k', 'breath 3–4 kHz'), ('flutter_100-500', 'flutter 0.1–0.5 kHz'), ('flutter_4000-8000', 'flutter 4–8 kHz'), ('crackle', 'crackle')] vers = [('e2e_F4', 'F4', BLUE_LIGHT, 'o'), ('e2e_F4_sharp', 'F4 + post-filter', BLUE_MID, 's'), ('e2e_G2_t6_hb_sharp', 'G2 + post-filter', BLUE_DARK, 'D'), ('e2e_FT4_G3_ft4_hb_sharp', 'FT4 + G3 (published)', RELEASE, '^')] fig, ax = plt.subplots(figsize=(W, 2.9)) for i in range(len(stats)): if i % 2 == 0: ax.axhspan(i - 0.5, i + 0.5, color=BAND, zorder=0, lw=0) for x in (-0.3, 0.3): ax.axvline(x, color=RULE, lw=0.6, ls=(0, (3, 2)), zorder=1) ax.axvline(0, color=MUTED, lw=0.8, zorder=1) step = 0.19 for j, (d, lab, col, mk) in enumerate(vers): v = json.load(open(os.path.join(RES, d, 'voice_stats.json')))['nano'] ys = [i + (j - (len(vers) - 1) / 2) * step for i in range(len(stats))] ax.scatter([v[k] for k, _ in stats], ys, s=24 if mk != '^' else 30, color=col, marker=mk, zorder=3, label=lab, edgecolor='white', linewidth=0.5) ax.set_yticks(range(len(stats)), [s[1] for s in stats]); ax.set_ylim(len(stats) - 0.5, -0.5) ax.set_xlim(-0.75, 0.75); ax.set_xticks([-0.6, -0.4, -0.2, 0, 0.2, 0.4, 0.6]) ax.set_xticklabels(['−0.6', '−0.4', '−0.2', '0', '+0.2', '+0.4', '+0.6']) ax.set_xlabel('offset from Kokoro-82M, in Kokoro\'s standard deviations across clips') ax.tick_params(axis='y', length=0, pad=6) ax.legend(ncol=4, loc='lower right', bbox_to_anchor=(1.0, 0.99), handletextpad=0.2, columnspacing=1.3, markerscale=1.0) save(fig, 'offsets') if __name__ == '__main__': params(); listening(); offsets()