"""Track A step 4: 1, 2, 4, 8, 16 concurrent streams against the endpoint. Every stream speaks a question in real time, ends its turn with input.commit (so the number is the model and the audio path, not an endpointing wait), and listens to the whole reply. Per turn: ttfa_ms input.commit sent -> first reply audio frame received (client clock) underruns frames that were due while the reply was playing but were not ready (server count) max_gap_ms longest gap between two reply audio frames at the client (80 ms is nominal) A level PASSES when every turn has ttfa_ms < 800 and no turn has an underrun. Streams start within a random 2 s of each other; they are not artificially aligned. python -m serving.loadtest --wav-dir eval/data/bba --out eval/results/loadtest """ import argparse import asyncio import random from pathlib import Path import aiohttp import numpy as np from duplex.spec import OUT_SR, write_json, write_wav from eval.ws_client import load_16k, open_session, percentiles, run_turn from serving.probe_baseline import gpu_memory async def stream(http, args, wavs, idx, level): await asyncio.sleep(random.Random(f"{level}-{idx}").uniform(0, 2.0)) ws = await open_session(http, args.url, args.system, "manual") turns = [] try: for k in range(args.turns): r = await run_turn(ws, wavs[(idx + k) % len(wavs)], commit=True, max_wait_s=args.max_wait_s) done = r["done"] or {} if args.save_audio and idx == 0 and r["audio"]: # one stream's replies, to check the audio with a recogniser name = Path(args.save_audio) / f"level{level}_turn{k}" write_wav(name.with_suffix(".wav"), np.frombuffer(r["audio"], dtype="