"""Build data/labels.parquet for ADD22_eval_31 (labels-only) from the local protocol. The audio is NOT redistributed (CC BY-NC-ND 4.0). The arena only ever needs the labels: reproduce --scoring and validate-dataset --labels-only read this parquet and never touch audio. This script reads ONLY the protocol text file (no audio decode, never writes into the source dir). utterance_id = the audio filename stem, e.g. "ADD_E3_00000000" (matches the notes.utterance_id the original audio packaging used). label is int8 with the package convention 0 = bonafide, 1 = spoof (higher score = more bonafide): genuine -> 0 (bonafide), fake -> 1 (spoof). """ from pathlib import Path import pyarrow as pa import pyarrow.parquet as pq SRC = Path("/home/kirill/mnt/users_4tb/datasets/add22track31test") LABEL_FILE = SRC / "track3_R1_label.txt" OUT = Path(__file__).resolve().parent / "data" / "labels.parquet" LABEL_MAP = {"genuine": 0, "fake": 1} # 0 = bonafide, 1 = spoof EXPECT_TOTAL = 112861 EXPECT_BONAFIDE = 20776 EXPECT_SPOOF = 92085 rows: dict[str, int] = {} for line in LABEL_FILE.read_text().splitlines(): line = line.strip() if not line: continue fname, raw = line.split() stem = fname[:-4] if fname.endswith(".wav") else fname if raw not in LABEL_MAP: raise ValueError(f"unexpected label {raw!r} on line: {line!r}") if stem in rows: raise ValueError(f"duplicate utterance_id: {stem!r}") rows[stem] = LABEL_MAP[raw] # Deterministic order (sorted by utterance_id) so the parquet is reproducible. uids = sorted(rows) labels = [rows[u] for u in uids] n_total = len(uids) n_bonafide = labels.count(0) n_spoof = labels.count(1) print(f"total={n_total} bonafide={n_bonafide} spoof={n_spoof}") assert n_total == EXPECT_TOTAL, (n_total, EXPECT_TOTAL) assert n_bonafide == EXPECT_BONAFIDE, (n_bonafide, EXPECT_BONAFIDE) assert n_spoof == EXPECT_SPOOF, (n_spoof, EXPECT_SPOOF) schema = pa.schema([("utterance_id", pa.string()), ("label", pa.int8())]) table = pa.table( {"utterance_id": pa.array(uids, pa.string()), "label": pa.array(labels, pa.int8())}, schema=schema, ) OUT.parent.mkdir(parents=True, exist_ok=True) pq.write_table(table, OUT) print(f"wrote {OUT} ({OUT.stat().st_size/1e6:.2f} MB)")