#!/usr/bin/env python3 """CPU/file-IO benchmark: python-soundfile vs stdlib wave on the same synthetic WAV. Run: python3 replay.txt --output-dir NEW_DIRECTORY Requires CPython 3.14 on macOS arm64 with numpy already installed (measured: 2.4.4). soundfile is imported if present; otherwise it is installed with pip into a temporary directory (needs access to PyPI; removed at exit). No key, no login, no paid API. The WAV is generated in memory by deterministic integer arithmetic (LCG + triangle wave, no random module, no external files, NOT speech). All WAV files are written under a tempfile.TemporaryDirectory and deleted at exit. Only NEW_DIRECTORY is kept. No audio device, no GPU. This measures file read/write speed and sample equality only; it does not measure transcription, audio quality or any inference. """ import argparse from datetime import datetime, timezone import gc import hashlib import json import os from pathlib import Path import platform import statistics import subprocess import sys import tempfile import time import wave TRIALS = 7 RATE = 44100 SECONDS = 60 CHANNELS = 2 TOOLS = ['wave', 'soundfile'] LOG = [] def log(msg): LOG.append(msg) print(msg, flush=True) def sha(data): return hashlib.sha256(data).hexdigest() def dump(path, value): with Path(path).open('x', encoding='utf-8') as f: json.dump(value, f, ensure_ascii=False, indent=2, allow_nan=False) def make_samples(np): """Deterministic int16 stereo: triangle tone + LCG noise. Returns (frames, channels) array.""" n = RATE * SECONDS s = 987654321 noise = np.empty(n * CHANNELS, dtype=np.int64) for i in range(n * CHANNELS): s = (s * 6364136223846793005 + 1442695040888963407) % (1 << 64) noise[i] = (s >> 40) % 2001 - 1000 t = np.arange(n, dtype=np.int64) tri_l = np.abs((t * 440 * 4) % (RATE * 4) - RATE * 2) * 8000 // (RATE * 2) - 4000 tri_r = np.abs((t * 660 * 4) % (RATE * 4) - RATE * 2) * 8000 // (RATE * 2) - 4000 tone = np.stack([tri_l, tri_r], axis=1).reshape(-1) return (tone + noise).astype('