AssemblyAI-STT-3.7-Realtime-Agent — voice notes to structured fields
# AssemblyAI-STT-3.7-Realtime-Agent: voice notes → structured work order
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-agent",
"language_detection": "true", # tag each turn with detected language
"keyterms_prompt": json.dumps([
"Carrier 50XC", "Trane XR", "scroll assembly",
"compressor seized", "refrigerant leak",
"3BAK-0601", "FS-20260518",
]),
"speaker_labels": "true", # tech vs. customer on-site
})
async def stream_field_notes(audio_iter, send_to_fsm):
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 turn → LLM Gateway extracts {wo_id, part, status}
fields = extract_work_order_fields(evt["transcript"])
send_to_fsm(fields)
Want the agent to talk back? Add LLM Gateway and the Text-to-Speech API, with reference implementations for LiveKit and Pipecat.