# Bilingual Live Diarized Storytelling Stream — PoC & 45-Minute A/B Experiment Kit

This kit accompanies [Bilingual voice stream: a silent cartographer prototype](/poc-bilingual-storytelling-stream/) and the browser workbench at [/interactive/bilingual-storytelling-stream/](/interactive/bilingual-storytelling-stream/).

Its goal is narrow and falsifiable: test whether a **zero-audio peripheral whisper rail** over bilingual Mandarin + English family talk preserves room warmth and unlocks richer episodic recall than bare oral-history questioning—without turning a visit into a monitored interview.

## Files in this kit

| File | Role |
| --- | --- |
| `session_runner.py` | Python 3 runner supporting zero-key `--demo` replay and `--live` Gemini Live API streaming (`google-genai >= 2.3.0`). |
| `sample_session.jsonl` | Synthetic, anonymized 12-turn (5.75 min) Mandarin + English code-switching storytelling fixture (`Host` + `Parent`). |
| `demo_output/session_events.jsonl` | Structured event log emitted by `--demo` (turns, code-switch spans, extracted entities, dwell-gated whisper cues). |
| `demo_output/scorecard.json` | Machine-readable evaluation scorecard for `--demo` (explicitly marked `synthetic_anonymized_fixture`). |

---

## 1. Zero-key quickstart (`--demo`)

Requires Python 3.10+ and **no external packages or API keys**:

```bash
python3 session_runner.py --demo
```

This replays `sample_session.jsonl`, runs deterministic bilingual CJK/Latin code-switch segmentation, extracts candidate entities and timeline gaps, enforces the 75-second Whisper Rail dwell gate at `0 dB` spoken output, evaluates diarization accuracy, and writes `demo_output/session_events.jsonl` and `demo_output/scorecard.json`.

---

## 2. Live streaming setup (`--live`)

Uses the current **`google-genai`** Python SDK (`>= 2.3.0`) over WebSockets. Do not install legacy `google-generativeai`.

```bash
pip install -U "google-genai>=2.3.0" sounddevice
export GEMINI_API_KEY="<your-key>"
```

### Option A: `gemini-3.8-live` silent non-blocking tool stream (default)

Streams 16 kHz mono 16-bit PCM audio, enables sliding-window context compression and session resumption handles for sessions exceeding 10–15 minutes, receives structured `NON_BLOCKING` function calls (`log_diarized_turn`, `emit_whisper_cue`), and enforces a **client-side 0 dB mute sink** (no speaker stream is ever opened):

```bash
python3 session_runner.py --live \
  --engine live-agent \
  --dwell-seconds 75 \
  --vocab "Cedar Street,River Road,Mid-Autumn Festival" \
  --out-dir ./trial_block_b
```

### Option B: `gemini-3.5-transcribe-live` text-only streaming transcription

Uses `response_modalities=["TEXT"]` with automatic multilingual detection (`language_codes=[]`) and local deterministic cue-gap gating:

```bash
python3 session_runner.py --live \
  --engine transcribe \
  --out-dir ./trial_block_b
```

To test against a recorded 16 kHz mono 16-bit WAV file instead of a live microphone, pass `--wav path/to/clip.wav`.

---

## 3. The 45-minute counterbalanced A/B family storytelling protocol

Before claiming any whisper rail beats ordinary conversation, run a within-pair trial with one Host and one Parent or close relative who naturally code-switches between Mandarin and English.

### Consent & privacy boundary (non-negotiable)

1. Obtain explicit verbal agreement from both people **before** touching record.
2. Place the microphone or phone face-down or visibly latched; never capture covertly.
3. State clearly that audio stays local by default (or if using `--live`, that audio streams to Gemini API during Block B only) and that the guest can delete the recording before leaving the table.
4. Keep the Host peripheral cue screen off the guest's sightline (e.g., matte laptop edge or pocket phone on Do Not Disturb, brightness dimmed, **no live scrolling transcript**).

### Schedule (45 minutes total)

Counterbalance order across sessions or pairs: odd pairs run **A → B**, even pairs run **B → A**. Assign two comparable life eras or two sets of 3–4 old artifacts so neither block exhausts the same story.

| Window | Phase | Protocol |
| --- | --- | --- |
| `00–05 min` | Consent & calibration | Confirm mute latch, mic placement, and counterbalanced order (`A→B` or `B→A`). Choose two distinct eras/photo sets. |
| `05–20 min` | **Block A (15 min): Bare oral-history baseline** | No whisper rail, no photo cues. Host asks open oral-history questions about Era 1 from memory or a short paper topic list. Record audio locally for scoring only. |
| `20–25 min` | Quiet tea / water reset | Five minutes off-task with recording paused so fatigue or warm-up momentum does not bleed directly across blocks. |
| `25–40 min` | **Block B (15 min): Sparse artifacts + Silent Cartographer** | Place 2–3 sparse undated photos/artifacts on the table for Era 2. Run the Silent Cartographer whisper rail (`0 dB` audio, max 1 bare anchor cue, `>= 75s` dwell, zero scripted prompts). Host may glance silently or ignore every cue. |
| `40–45 min` | Blinded comfort rating & debrief | **Before reading transcripts**, Guest and Host independently rate room comfort (1–5) for Block A and Block B, then answer one qualitative prompt: *"Did the setup ever feel like an interview or surveillance?"* |

### Scoring rubric (score both blocks blind to condition where possible)

| Metric | Operational definition | What beats the baseline |
| --- | --- | --- |
| **1. Concrete episodic details / min** | Count specific sensory anchors, named micro-events, physical objects, or causal sequences (e.g., *"rice-cooker lid warming cold hands"*) divided by 15.0 min. Exclude generic summaries (*"winter was hard"*). | Block B > Block A without lengthening Host talk time. |
| **2. Newly resolved entities, dates & artifacts** | Count people/roles, places, year/month bounds, or undated photos newly disambiguated or corrected during the block. | Block B resolves more orphan items or catches more date drift. |
| **3. Floor preservation & pause integrity** | (a) Ratio of Parent-to-Host spoken units; (b) share of `>= 2s` memory-search pauses left unbroken; (c) Host downward gaze breaks per 5 min. | Unbroken pauses `>= 90%`, Parent:Host floor ratio maintained, gaze breaks `<= 2` per 5 min. |
| **4. Subjective room-comfort score (1–5)** | Separate 1–5 ratings from Guest and Host (`1 = stiff/monitored`, `3 = neutral`, `5 = completely warm and natural`). | Guest comfort in Block B `>=` Block A (a `>= 1`-point drop falsifies calm presence even if recall rises). |

### Falsification rule

If Block B raises episodic details/min **only** by dropping Guest room-comfort below Block A, or if the Host's glances at the whisper rail trigger visible hesitation, the Silent Cartographer rail fails its primary design invariant and must be simplified further (e.g., post-session cues only, zero mid-talk rail).

---

## 4. Reporting results

You can run the timer, local browser recorder, and A/B scorecard with zero backend at [/interactive/bilingual-storytelling-stream/](/interactive/bilingual-storytelling-stream/), and share anonymized aggregate scores (never raw family audio or private names) via [/talk/](/talk/).
