Overview
Contact centers handling financial services, insurance, or healthcare operate under strict regulatory requirements. Agents must follow scripts, disclose specific information, and avoid prohibited language. Traditional QA reviews 2–5% of calls after the fact. By the time a violation is caught, it has already happened hundreds of times. This guide shows you how to build a system that monitors every call in real time. Audio streams to the Gnani Prisma v2.5 WebSocket STT API. Transcripts arrive within milliseconds of speech completion. A compliance and quality engine processes each segment, matches against rule sets, and fires alerts to your backend — while the call is still live.Architecture
The system has three logical layers: audio ingestion, transcription, and monitoring. Each runs concurrently in an async event loop.Prerequisites
Authentication
Authentication is performed at connection time via HTTP headers on the WebSocket upgrade request. There is no separate auth step — the connection either opens or returns 401.End-to-End Workflow
Call starts — open WebSocket connection
wss://api.vachana.ai/stt/v3/stream with auth headers and language config. A session object is created and keyed to the call ID.Receive connected event — confirm config
connected event confirming sample rate and chunk size. Any mismatch (wrong sample rate, unsupported language) surfaces immediately.Stream audio in 1024-byte frames
VAD triggers — receive processing event
processing event. Use this timestamp to measure speech-to-transcript latency and to start a silence timer in the quality engine.Transcript arrives — run compliance and quality engines
transcript event carries text, segment_index, audio_duration_ms, and latency. Both engines process the text synchronously. Alerts are dispatched async so they never block the next transcript.Alerts fire — supervisor is notified
CRITICAL hits the supervisor dashboard immediately; WARNING queues for post-call review.Call ends — flush session
Connecting to the WebSocket API
The SDK’sGnaniSTTStreamClient wraps the WebSocket connection, frame pacing, and event parsing. Use it as an async context manager.
Streaming Audio
Audio format requirements
WebSocket Event Reference
latency field (milliseconds from end of speech to transcript delivery) is your primary observability metric for pipeline health. Track p50, p95, p99 per call session and alert if p95 consistently exceeds your SLA threshold.Compliance Detection
The compliance engine runs on eachtranscript event. It checks segment text against three rule categories: prohibited keywords, risk phrases, and required disclosures. All checks are synchronous string operations — they complete in under 1ms per segment.
Quality Monitoring
Error Handling & Reconnect Logic
WebSocket connections drop. The reconnect loop below uses exponential backoff with full jitter and caps at a configurable maximum. Session state is preserved across reconnects usingprocessed_indices to deduplicate segments.
Production Best Practices
Concurrency model
Concurrency model
asyncio.Task. The audio producer and event consumer run concurrently within that task. Do not use threads — the WebSocket library is async-native. A single well-tuned Python process handles 100+ concurrent calls comfortably; the bottleneck is network I/O, not CPU.Alert dispatch — never block the transcript consumer
Alert dispatch — never block the transcript consumer
asyncio.create_task(). A slow downstream system under load must never delay the next transcript event.Latency optimization
Latency optimization
Key metrics to track per session
Key metrics to track per session
Debugging
Full Runnable Example
What to Build Next
- Speaker Diarization — Separate agent and customer voices. Attribute compliance hits to the correct speaker.
- Sentiment Analysis — Feed each segment’s text to a sentiment model. Track the sentiment arc across the call.
- Agent Assist — On each
transcriptevent, call an LLM with the running conversation context to surface next-best-action suggestions in real time. - LLM Summarisation — At call end, send the full session transcript to an LLM for structured output: issue, resolution, action items, disposition.
- Compliance Scoring — Build a per-call compliance score (0–100) based on rule severity, frequency, and placement in the call.
pip install gnani-vachana