AssemblyAI-STT-3.7-Realtime — live transcript for agent desktop
# AssemblyAI-STT-3.7-Realtime: live transcript for an agent assist desktop
import asyncio, json, websockets
from urllib.parse import urlencode
API_KEY = "YOUR_API_KEY"
params = urlencode({
"sample_rate": 16000,
"speech_model": "assemblyai-stt-3-7-realtime",
"keyterms_prompt": json.dumps([
"cancel", "supervisor", "refund",
"order #", "account number",
]),
"speaker_labels": "true", # diarize agent vs. caller
"redact_pii": "true", # mask PII before it hits the UI
"redact_pii_policies": json.dumps([
"credit_card_number", "us_social_security_number",
"date_of_birth", "phone_number", "email_address",
]),
"redact_pii_sub": "entity_name", # e.g. [CREDIT_CARD_NUMBER]
})
async def stream_agent_assist(audio_iter):
url = f"wss://streaming.assemblyai.com/v3/ws?{params}"
async with websockets.connect(
url, additional_headers={"Authorization": API_KEY},
) as ws:
async def send_audio():
async for chunk in audio_iter:
await ws.send(chunk)
asyncio.create_task(send_audio())
async for raw in ws:
evt = json.loads(raw)
if evt.get("type") == "Turn" and evt.get("end_of_turn"):
# finalized, PII-redacted turn — pipe to LLM Gateway for coaching
push_to_coach(evt["transcript"], evt.get("speaker_label"))
Want an AI tier-1 agent in front of your human team? Pair this transcript with LLM Gateway and the Text-to-Speech API.