Skip to main content

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.
Which API to use? This use case uses the WebSocket STT API for real-time streaming. For post-call batch analysis, see the Call Analytics Pipeline.

Architecture

The system has three logical layers: audio ingestion, transcription, and monitoring. Each runs concurrently in an async event loop.
Each call owns an isolated session object that tracks the full transcript buffer, a timeline of events, compliance status, quality metrics, and reconnect context. This state survives WebSocket reconnects and is flushed to your store at call end.

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.
.env
Never hardcode API keys. Load credentials from environment variables or a secrets manager. The x-api-key-id header is visible in plaintext in WebSocket upgrade logs — ensure those logs are access-controlled.

End-to-End Workflow

1

Call starts — open WebSocket connection

Your telephony bridge fires a call-start event. The monitor opens a WebSocket to wss://api.vachana.ai/stt/v3/stream with auth headers and language config. A session object is created and keyed to the call ID.
2

Receive connected event — confirm config

The server returns a connected event confirming sample rate and chunk size. Any mismatch (wrong sample rate, unsupported language) surfaces immediately.
3

Stream audio in 1024-byte frames

An async producer task reads PCM frames from the telephony tap and sends them at real-time cadence: one 1024-byte frame every 32ms for 16kHz audio. Bursting frames degrades VAD accuracy.
4

VAD triggers — receive processing event

When VAD detects end-of-speech, the server sends a processing event. Use this timestamp to measure speech-to-transcript latency and to start a silence timer in the quality engine.
5

Transcript arrives — run compliance and quality engines

The 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.
6

Alerts fire — supervisor is notified

Compliance violations and quality alerts go to the alert dispatcher. Severity determines the channel: CRITICAL hits the supervisor dashboard immediately; WARNING queues for post-call review.
7

Call ends — flush session

On call end, close the WebSocket gracefully. Run final session-level checks (e.g. required disclosure was never spoken). Flush session state to your store and emit a call-complete summary event.

Connecting to the WebSocket API

The SDK’s GnaniSTTStreamClient wraps the WebSocket connection, frame pacing, and event parsing. Use it as an async context manager.
basic connection

Streaming Audio

Audio format requirements

Each WebSocket frame must be exactly 1024 bytes. Bursting frames (sending faster than real time) degrades VAD accuracy — the VAD model is trained on real-time cadence.
audio producer task

WebSocket Event Reference

transcript event
The 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 each transcript 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.
rules/compliance.json
ComplianceEngine

Quality Monitoring

rules/quality.json
QualityEngine

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 using processed_indices to deduplicate segments.
reconnect loop

Production Best Practices

Each active call runs in its own 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.
Compliance and quality checks run synchronously (sub-millisecond string matching). Alert dispatch — HTTP webhooks, queue publishes, database writes — must always be fire-and-forget via asyncio.create_task(). A slow downstream system under load must never delay the next transcript event.

Debugging


Full Runnable Example

monitor.py

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 transcript event, 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.
Related docs: WebSocket STT API · Batch STT for post-call analysis · SDK install: pip install gnani-vachana