File size: 3,149 Bytes
c202fc8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
"""Synthetic-rating alignment per TTS voice (Table 12).

    python analysis/06_voice_study/06_synth_alignment.py

For each (voice, synthetic rater): per-clip mean synthetic rating against
per-clip mean human rating, over the 60 clips of the 30 voice-study prompts.
Pearson r, Spearman rho, MAE, and mean signed difference (synthetic − human;
positive = synthetic rater above human).

Human means come from the analyzed rater set (attention-check exclusions
applied): the new voice arms from long_voice_normalized.csv, the af_heart
baseline from the main study's long_audio_table_normalized.csv restricted to
the same 30 prompts. Synthetic means average the 10 draws per clip; the
baseline draws are the main study's runs (data/main_study/synth_long_audio_*), the
new voice arms the re-rendered runs in data/voice_study/synth/.
"""

from __future__ import annotations

from pathlib import Path

import pandas as pd
from scipy import stats

ROOT = Path(__file__).resolve().parent.parent.parent
VOICE_DATA = ROOT / "data/voice_study"
CONTEXT_DATA = ROOT / "data/audio_context_study"
DERIVED = ROOT / "results/06_voice_study"
SD = ROOT / "data/main_study"

MODELS = ["gpt4o", "gemini_36_flash", "qwen35_omni_flash"]
ARMS = ["kokoro_am_michael", "chatterbox", "qwen3tts_serena"]


def clip_means(df: pd.DataFrame) -> pd.Series:
    return df.groupby("AudioClip")["Rating"].mean()


def align(h: pd.Series, s: pd.Series) -> dict | None:
    m = pd.concat([h.rename("h"), s.rename("s")], axis=1).dropna()
    if len(m) < 3:
        return None
    return dict(clips=len(m),
                r=stats.pearsonr(m.h, m.s)[0],
                rho=stats.spearmanr(m.h, m.s)[0],
                mae=(m.s - m.h).abs().mean(),
                signed=(m.s - m.h).mean())


def main() -> None:
    prompts = set(pd.read_csv(ROOT / "stimuli/voice_study/prompts.csv")["PromptID"])

    human = {}
    voice = pd.read_csv(VOICE_DATA / "long_voice_normalized.csv")
    for arm, g in voice.groupby("Arm"):
        human[arm] = clip_means(g)
    base = pd.read_csv(SD / "long_audio_table_normalized.csv")
    base = base[~base["IsAttentionCheck"].astype(bool)]
    base = base[base["PromptID"].isin(prompts)]
    human["kokoro_af_heart (baseline)"] = clip_means(base)

    rows = []
    for voice_name, h in human.items():
        for model in MODELS:
            if "baseline" in voice_name:
                path = SD / f"synth_long_audio_table_{model}.csv"
            else:
                path = (VOICE_DATA / "synth" /
                        f"synth_long_audio_table_{voice_name}_{model}.csv")
            if not path.exists():
                continue
            s = pd.read_csv(path)
            s = s[s["PromptID"].astype(str).isin(prompts)]
            res = align(h, clip_means(s))
            if res:
                rows.append(dict(voice=voice_name, rater=model, **res))

    out = pd.DataFrame(rows)
    print(out.to_string(index=False, float_format=lambda v: f"{v:.3f}"))
    out.to_csv(DERIVED / "synth_alignment_by_voice.csv", index=False)
    print(f"\n -> results/06_voice_study/synth_alignment_by_voice.csv")


if __name__ == "__main__":
    main()