asyncio is inconvenient. This walkthrough targets the true live capture API (/analyze/live/*) that streams transcripts, emotion, and cognitive analytics as the media arrives. It is not the Replay endpoint (POST /analyze/stream), which simply replays an uploaded file.
Endpoint Reference
All requests require
X-API-Key, and live capture must be enabled on the deployment (ENABLE_LIVE_STREAMING=true).
Requirements
- Audio input: 16-bit PCM WAV, MP3, or Opus are safe defaults (server handles transcoding).
- Chunking: 32–128 kB provides good latency without overwhelming FastAPI.
- SSE: Only one consumer may connect to
events_endpointper session.
Recipe 1 – Start a session & read SSE synchronously
status, final_transcript, emotion, cognitive, transition, moment, summary_update, error, done.
Recipe 2 – Stream audio chunks synchronously
chunk_seqmust be exactly0,1,2.... On retry, resend the same sequence number.- Keep chunk sizes consistent; smaller chunks reduce latency but increase HTTP overhead.
- The server rejects additional chunks after you send
finalize.
Recipe 3 – Control the session
Recipe 4 – Full synchronous runner with threads
To ingest while listening for analytics, use a background thread for SSE.Production Notes
- Replace the file reader with microphone capture: enqueue PCM frames and write them out via
upload_chunkswithout staging on disk. - Add exponential backoff & retry for
requests.postcalls; resend the samechunk_seqif you get a transient network error. - If the SSE thread exits without a
doneevent, inspect the lasterrorpayload and consider restarting the session. - Monitor
/metricsforeventscounts and agent latency to ensure the live service keeps up with ingest. - Artifacts (timeline, summary, segmentation, agent outputs) are persisted and referenced by the final
doneevent.