PART 2 · part 1: the batch classifier
Labeling a Church Service, Live
Part 1's classifier could read the whole service before deciding. The live one gets two seconds at a time.
Part 1 ended on an honest limitation. The batch classifier's smoother, Viterbi, is non-causal: it reads the whole service before it labels the first window, and that hindsight is exactly where its power comes from. A live version, we said, would have to trade some of that power for latency. This post is about that trade, because the live version now exists: a WebSocket endpoint that takes raw audio as it happens and pushes back a label, a full probability distribution, and a growing segment timeline every two seconds. The /live page still plays a simulation for visitors, but behind an access token it now drives this real pipeline from your microphone.
What's interesting is how little changed, and where. Perception is untouched: the same
parakeet ASR model, on the same kind of GPU. Judgment is untouched: the same Jev Choice
question over the same eight criteria, down to the same file (the server bakes part 1's
classify.py into its image and calls the same function1).
Exactly two things had to be rebuilt: what Jev gets told, and the smoother. Both for the
same reason: the future stopped being available.
A window that slides
The batch pipeline cut the finished recording into 184 fixed windows and judged each one once. The live pipeline keeps one window and moves it. The server holds a rolling buffer of the last 30 seconds of audio it has received, and every 2 seconds of incoming audio it runs a hop: transcribe the whole buffer, ask Jev the one multiple-choice question, push the answer to the client.
The protocol around this is small. The client opens a WebSocket, authenticates, and streams raw PCM; the server answers every hop:
client: {"type": "start", "token": "...", "sample_rate": 16000}
server: {"type": "ready", "hop_seconds": 2.0, "window_seconds": 30.0,
"categories": [...the 8...]}
client: <binary frames: raw 16-bit mono PCM, any chunking>
server: {"type": "update", "t": 12.2, "label": "sermon",
"probabilities": {"sermon": 0.75, "mc": 0.14, ...},
"segments": [{"start": 0.0, "end": 8.2, "label": "mc"},
{"start": 8.2, "end": 12.2, "label": "sermon"}],
"transcript_tail": "...", "words_per_minute": 70.0} ← every hop
client: {"type": "stop"}
server: {"type": "ended", "duration": 50.0, "segments": [...]}
The cost shape changes accordingly. Batch asked Jev once per 30 seconds of audio, about 120 calls per hour. Live asks once per 2-second hop: 30 calls a minute, 1,800 an hour, 15× the batch rate, plus a GPU container that stays resident for the whole session with parakeet loaded. That is the standing price of answers that arrive while the service is still happening.
What Jev no longer gets to see
Part 1 made a point of the state object: every field earned its place. Live, two of those fields are unbuildable, and the comparison says a lot about what streaming really costs:
| Field | Batch | Live |
|---|---|---|
transcript | the window's words, 1,500-char cap | same |
words_per_minute | the music detector | same |
previous_window_tail | last 300 chars before the window | same idea: tail of the previous hop |
next_window_head | first 300 chars after the window | gone. The future hasn't happened. |
position_in_service_pct | 32.1% into the service | gone. Percent of an unknown total is unknowable. |
elapsed | — | new: minutes since the stream began |
The second deletion is the painful one. Part 1 showed that pre_roll versus
post_roll, and worship versus closing_song, are
distinguished almost entirely by the clock: the text can be identical, position decides.
Live, Jev only knows that 14 minutes have elapsed, not whether that is the middle of a
90-minute service or the end of a 15-minute one. Those category pairs are genuinely harder
now, and no engineering inside this pipeline fixes it; only context from outside (a planned
service length, say) could put that signal back.
A smoother that can't wait
Viterbi's replacement is almost embarrassingly simple, and the simplicity is the point. The live rule is:
When a switch is confirmed, the boundary is backdated to where the streak began, so a confirmed segment starts where the evidence started, 4 seconds in the past. That backdating is the whole latency bill: the timeline you see is final everywhere except its last 4 seconds.
Compare the two bars. Batch: a label change had to buy back a 12× probability ratio (e2.5), judged against every window in the service at once. Live: a label change has to persist for 4 seconds of hops, probabilities not consulted. One is an evidence bar, the other is a patience bar. Here is a real 50-second session, streamed in real time through the deployed endpoint, and it happens to be the same stretch of audio as part 1's example window2:
Read the trace left to right and the whole design shows itself:
- The cold open is noise, and the rule absorbs it. The first hops see
2, 4, 6 seconds of audio in a 30-second window: almost no words, so Jev guesses
worship_hybrid0.42, thenworship0.47 at 0 words/minute. None of it survives, because none of it wins twice in a row. - A confirmed switch, backdated.
sermonwins at 10.2s (0.47) and again at 12.2s (0.75). Two in a row: the timeline flips, and the boundary is written at 8.2s, where the streak began, not at 12.2s where it was confirmed. - A flicker dies alone. At 19.0s one hop says
mc0.47. The displayed label never moves. This is the live counterpart of part 1's one-windowvideoisland, suppressed by patience instead of by log-probability arithmetic. - And the rule's weakness, on camera. At 34.8s and 36.8s,
mcwins twice with the unimpressive scores 0.44 and 0.46, so a 6-secondmcsegment opens, and two hops latersermontakes the timeline back. Batch Viterbi, consulting the actual probabilities against its 12× bar, would likely have absorbed that wobble. The live rule can't: it counts streaks, not evidence. That segment is the price of ignoring the probabilities, paid on screen.
That last item is the honest open problem. The distributions are all there in every update; the smoother just doesn't read them yet. A probability-weighted causal smoother, Viterbi run over a short lag buffer, would spend the same 4 seconds of latency and buy real evidence-weighing with it. The current rule was chosen because it is simple, legible, and wrong in ways you can see; that is a good place for a v1 smoother to be.
The hop loop under pressure
Three details of the loop do most of the operational work:
- Hops are counted in audio, not wall time. A hop fires when 2 more seconds of audio have arrived. A microphone delivers that every 2 real seconds; a file can deliver it as fast as the network allows, which is how the same endpoint does faster-than-realtime backfill with no second code path.
- Overload sheds, it doesn't queue. One hop runs at a time. If transcription plus Jev takes longer than a hop, or audio arrives faster than realtime, due hops are simply skipped and the next hop judges a fresher window. In a test where the 50-second clip was pushed at full speed, the nominal 25 hops collapsed to 2 real ones, and the answer was still right. A backlog of stale windows would be strictly worse than fewer, fresher judgments.
- Stop flushes. On
stop, the server lets any in-flight hop finish and then runs one final hop before sendingended, so even a stream shorter or faster than the hop schedule gets a verdict on its tail.
A failed hop (a Jev rate limit, a transcription hiccup) is logged and dropped; the session lives and the next hop retries by construction, because the next hop was going to judge an overlapping window anyway. The sliding overlap is doing double duty as the retry mechanism.
Around the loop: sessions authenticate with a single bearer token (held as a Modal secret;
compared in constant time; wrong token closes with code 4401), idle for 30 seconds and
you're closed with 4408, stream past 3 hours and it's 4413. The GPU container keeps
parakeet loaded across sessions and serves two sessions at once behind a lock, with more
containers spinning up past that. The one operational gotcha: a cold first connection pays
roughly 70 seconds of container start, so clients probe the plain HTTP
/health route first and connect when it answers.
The browser is the microphone
On the /live page nothing changed for the public: no token, and the page runs the same labeled simulation as before. Paste the access token (key button) and the page switches drivers: microphone capture through an AudioWorklet, downsampled in the page to 16 kHz 16-bit PCM, sent as binary WebSocket frames; every server update then drives exactly the same lanes and per-category probability charts the simulation drove. The UI built against fake data in part 1's timeline turned out to be the real UI all along; the simulation was the spec.
Final thoughts
Part 1's pattern was: reduce the signal to text plus cheap numbers, ask a tightly-scoped question many times, recover known structure with classical algorithms. Streaming bent that pattern without breaking it. The question and the questioner are byte-identical; the reduction lost exactly the two inputs that required knowing the future; and the classical smoother was swapped for a cruder one whose failure mode is visible, bounded (4 seconds), and already demonstrated on a real trace, with its successor (lagged, probability-weighted smoothing) sitting in plain sight. The expensive part was never the intelligence; it was deciding what the intelligence is allowed to know, and how long it is allowed to wait before it must say something.
1 The streaming image adds part 1's
classify.py as a file and calls its call_jev(), so the
criteria definitions cannot drift between the batch and live pipelines; there is one
copy. ↩
2 The clip is 29:00–29:50 of ALinkExample.mp3, chosen to overlap part 1's example window (29:30–30:00, where batch Jev said sermon 0.75). The live hops over the same audio settle at sermon 0.76–0.80: two pipelines, one opinion. The uneven hop times in the trace (2.8, 4.2, 6.2…) are the one-at-a-time hop guard pushing the schedule back when a hop runs long. ↩