"""Blind A/B listening sheet: base vs Geetha (D-058), plus the Stage C tag check for arun. make copies the clips under neutral names, level-matched, writes blind\\listen.html and keeps the answer key OUTSIDE the folder the listener opens. score reads the answers file the page downloads and prints the tallies. Usage: python scripts\\make_blind_ab.py make python scripts\\make_blind_ab.py score E:\\path\\to\\blind_answers.json """ from __future__ import annotations import argparse import html import json import math import random import re import sys from pathlib import Path import numpy as np import soundfile as sf RUN = Path(r"E:\Geetha\runs\m3_base_vs_geetha") STAGEC = Path(r"E:\Geetha\runs\m3_breath_stagec_v3") OUT = RUN / "blind" KEY = RUN / "blind_key.json" # not inside OUT: the listener never sees it SEED = 2711 TARGET_RMS_DB = -23.0 # Same sentences the kernels spoke (t0..t7), breath marks removed for display. TEXTS = [ "நேத்து ராத்திரி ரொம்ப நேரம் வேலை பாத்துட்டு இருந்தேன், அதனால காலையில எந்திரிக்கவே முடியல, ஆபீஸுக்கு லேட்டா தான் போனேன்", "எங்க ஊர்ல மழை பெய்ய ஆரம்பிச்சா, ரெண்டு மூணு நாளைக்கு நிக்கவே நிக்காது, அப்போ எல்லாரும் வீட்டுக்குள்ளயே இருப்பாங்க", "சரி நான் ஒண்ணு சொல்றேன் கவனமா கேளு, இந்த விஷயத்த இப்போதைக்கு யார்கிட்டயும் சொல்ல வேண்டாம்", "இன்னைக்கு காலையில பஸ்ல வரும்போது ஒரு பழைய நண்பன பாத்தேன், ரொம்ப வருஷம் கழிச்சு பேசினோம், மனசுக்கு ரொம்ப சந்தோஷமா இருந்துச்சு", "அம்மா சொன்னாங்க சீக்கிரம் வீட்டுக்கு வான்னு, ஆனா வேலை முடியவே ராத்திரி ஆயிடுச்சு", "உண்மைய சொல்லணும்னா எனக்கு அந்த படம் அவ்வளவா பிடிக்கல, ஆனா பாட்டு மட்டும் நல்லா இருந்துச்சு", "கடைக்கு போய் காய்கறி வாங்கிட்டு வரலாம்னு நினைச்சேன், அதுக்குள்ள மழை வந்துடுச்சு", "இத பத்தி நாம நாளைக்கு பொறுமையா பேசலாம், இப்போ எனக்கு கொஞ்சம் ஓய்வு வேணும்", ] SECTIONS = { "plain": { "title": "Part 1 - plain speech (16 pairs)", "ask": "Which one sounds more like a real person talking?", "options": [("A", "A"), ("B", "B"), ("same", "No real difference")], }, "breath": { "title": "Part 2 - with a breath put in (16 pairs)", "ask": "Which one sounds more natural, breath included?", "options": [("A", "A"), ("B", "B"), ("same", "No real difference")], }, "tag": { "title": "Part 3 - arun only (4 pairs)", "ask": "In which one do you hear him breathe?", "options": [("A", "A"), ("B", "B"), ("both", "Both"), ("neither", "Neither")], }, } def level(src: Path, dst: Path) -> None: audio, rate = sf.read(src, dtype="float32") rms = float(np.sqrt(np.mean(audio ** 2))) or 1e-9 gain = (10 ** (TARGET_RMS_DB / 20)) / rms peak = float(np.max(np.abs(audio))) or 1e-9 gain = min(gain, 0.98 / peak) sf.write(dst, audio * gain, rate, subtype="PCM_16") def collect() -> list[dict]: pairs = [] clips = RUN / "clips" for path in sorted(clips.glob("*_base_*.wav")): match = re.fullmatch(r"(anitha|arun)_t(\d)_base_(plain|breath_lead|breath_mid)", path.stem) if not match: continue voice, text, arm = match.group(1), int(match.group(2)), match.group(3) other = clips / f"{voice}_t{text}_geetha_{arm}.wav" if not other.exists(): raise SystemExit(f"missing partner for {path.name}") pairs.append({"section": "plain" if arm == "plain" else "breath", "voice": voice, "text": text, "arm": arm, "x": ("base", path), "y": ("geetha", other)}) for text in range(4): tag = STAGEC / "clips" / f"arun_t{text}_C_tag.wav" notag = STAGEC / "clips" / f"arun_t{text}_C_notag.wav" if not (tag.exists() and notag.exists()): raise SystemExit(f"missing Stage C clips for arun t{text}") pairs.append({"section": "tag", "voice": "arun", "text": text, "arm": "stageC", "x": ("C_notag", notag), "y": ("C_tag", tag)}) return pairs def make() -> None: rng = random.Random(SEED) pairs = collect() OUT.mkdir(parents=True, exist_ok=True) for old in OUT.glob("p*_[AB].wav"): old.unlink() key, blocks, number = {}, [], 0 for name, section in SECTIONS.items(): mine = [p for p in pairs if p["section"] == name] rng.shuffle(mine) # half the pairs put the second system on side A, so a side habit cannot favour either flips = [i % 2 == 0 for i in range(len(mine))] rng.shuffle(flips) blocks.append(f"

{html.escape(section['title'])}

" f"

{html.escape(section['ask'])}

") for pair, flip in zip(mine, flips): number += 1 pid = f"p{number:02d}" a, b = (pair["y"], pair["x"]) if flip else (pair["x"], pair["y"]) level(a[1], OUT / f"{pid}_A.wav") level(b[1], OUT / f"{pid}_B.wav") key[pid] = {"section": name, "voice": pair["voice"], "text": pair["text"], "arm": pair["arm"], "A": a[0], "B": b[0], "A_src": str(a[1]), "B_src": str(b[1])} radios = "".join( f"" for value, label in section["options"]) blocks.append( f"
{number}
" f"
{html.escape(TEXTS[pair['text']])}
" f"
A" f"B
" f"
{radios}
" f"
") KEY.write_text(json.dumps({"seed": SEED, "target_rms_db": TARGET_RMS_DB, "pairs": key}, ensure_ascii=False, indent=1), encoding="utf-8") (OUT / "listen.html").write_text(PAGE.replace("@@BLOCKS@@", "\n".join(blocks)) .replace("@@TOTAL@@", str(number)), encoding="utf-8") print(f"{number} pairs -> {OUT / 'listen.html'}") print(f"key (do not open before listening) -> {KEY}") def wilson(wins: int, total: int) -> str: if total == 0: return "n/a" z, p = 1.96, wins / total centre = (p + z * z / (2 * total)) / (1 + z * z / total) half = z * math.sqrt(p * (1 - p) / total + z * z / (4 * total * total)) / (1 + z * z / total) return f"{100 * p:.0f}% [{100 * (centre - half):.0f}, {100 * (centre + half):.0f}]" def score(answers_path: Path) -> None: key = json.loads(KEY.read_text(encoding="utf-8"))["pairs"] data = json.loads(answers_path.read_text(encoding="utf-8")) answers, notes = data.get("answers", {}), data.get("notes", {}) missing = [pid for pid in key if pid not in answers] if missing: print(f"unanswered: {', '.join(missing)}") for name in ("plain", "breath"): for voice in ("anitha", "arun", "both"): tally = {"geetha": 0, "base": 0, "same": 0} for pid, row in key.items(): if row["section"] != name or pid not in answers: continue if voice != "both" and row["voice"] != voice: continue pick = answers[pid] tally["same" if pick == "same" else row[pick]] += 1 decided = tally["geetha"] + tally["base"] print(f"{name:6s} {voice:6s} geetha {tally['geetha']:2d} base {tally['base']:2d} " f"same {tally['same']:2d} geetha share of decided: {wilson(tally['geetha'], decided)}") heard = {"C_tag": 0, "C_notag": 0} rows = [(pid, row) for pid, row in key.items() if row["section"] == "tag" and pid in answers] for pid, row in rows: pick = answers[pid] for side in ("A", "B"): if pick == side or pick == "both": heard[row[side]] += 1 print(f"tag arun breath heard: with tag {heard['C_tag']}/{len(rows)}, " f"without tag {heard['C_notag']}/{len(rows)}") for pid, note in notes.items(): if note.strip() and pid in key: row = key[pid] print(f"note {pid} [{row['section']} {row['voice']} t{row['text']} {row['arm']} " f"A={row['A']} B={row['B']}]: {note.strip()}") PAGE = """ Geetha blind listen
0 of @@TOTAL@@ answered

Geetha blind listen - 15 Nov

Each row has the same sentence spoken twice, A and B. One is one system, one is another; which is which changes from row to row and is hidden.
Use headphones. Play A, play B, pick. Replay as often as you like. If you cannot tell, pick "No real difference" - that is a real answer, not a failure.
All clips are set to the same loudness, so louder never means better here.
Your picks are remembered if you close the page. At the end press Save answers and tell Claude it is done.
@@BLOCKS@@

Finished

A file blind_answers.json goes to your Downloads folder. The same text appears below in case the download is blocked.

""" def main() -> None: parser = argparse.ArgumentParser() sub = parser.add_subparsers(dest="command", required=True) sub.add_parser("make") scorer = sub.add_parser("score") scorer.add_argument("answers", type=Path) args = parser.parse_args() if args.command == "make": make() else: score(args.answers) if __name__ == "__main__": sys.stdout.reconfigure(encoding="utf-8") main()