"""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['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" A file blind_answers.json goes to your Downloads folder. The same text appears below in case the download is blocked.