Order lookup with live spoken bridge
Caller asks for order B42; agent speaks an immediate bridge (1,768 ms word-aligned latency), emits lookup_order(order_id="B42") asynchronously, and delivers the 3:00 p.m. ETA.
← Speech data prep and inference API
End-to-end bidirectional speech-to-speech WebSocket with native 80 ms full-duplex turn-taking, bounded natural play-through when the agent yields, curated streaming voices, and async client tool calling ($0.90 / connected hour, $0.015 / min).
Preview status: Live for all Trelis API accounts. Speech synthesis, turn-taking, and multilingual voice quality are actively improving during preview.
Unedited real-time recordings captured directly from WS /v1/duplex/speech(synthetic caller speech mixed with live duplex-speech-1 agent audio). All voices are AI-generated.
Caller asks for order B42; agent speaks an immediate bridge (1,768 ms word-aligned latency), emits lookup_order(order_id="B42") asynchronously, and delivers the 3:00 p.m. ETA.
While the agent walks through protection plans, the caller cuts in asking for appointment A19. The agent yields mid-sentence (1,288 ms), calls check_appointment(ref_code="A19"), and confirms Thursday at 10:30 a.m.
Caller asks in Italian about order B42; agent responds natively in Italian, runs lookup_order(order_id="B42"), and speaks the delivery window with natural European prosody.
One WebSocket handles live caller audio ingestion, full-duplex conversational timing, asynchronous tool execution, and streaming voice output with automatic cross-turn prosody continuation.
| WebSocket endpoint | wss://api.trelis.com/v1/duplex/speech (model=duplex-speech-1) |
|---|---|
| Pricing | $0.90 / connected hour ($0.015 / min), billed per connected second ($0.001 minimum). See pricing → |
| Languages | English (en), Spanish (es), French (fr), German (de), Italian (it), Portuguese (pt), Dutch (nl). Write system_prompt in the target language to set the opening greeting and reply language. |
| Caller audio input | Binary frames or base64 JSON audio frames: mono pcm_s16le, pcm_mulaw, or pcm_alaw at 8, 16, 24, or 48 kHz |
| Agent audio output | Binary PCM16 frames or base64 JSON agent.audio frames at 24000 (default), 48000, or 16000 Hz (output_sample_rate) |
| Turn-taking & yielding | The 80 ms duplex clock stays listening on every tick while streaming speech continuously within a bounded commitment window. When the caller interrupts and the model yields, the server emits agent.speech.pause (reason="barge_in") and lets the short committed tail play through naturally without cutting off words mid-syllable |
| Async tool calling | Declare up to 64 OpenAI-format tools in session.start; receive agent.tool_call events and return tool.result asynchronously without pausing listening; cancel stale calls with tool.cancel |
| Built-in voices | Pass voice in session.start (default, neutral_male, calm_female, clear_female, british_female, deep_male, clear_male, british_male) for low-latency incremental word-by-word streaming |
14 live real-time voice calls (8 English direct and tool-calling turns plus 6 non-English European tool calls across ES, FR, DE, IT, PT, and NL) streamed at 16 kHz / 80 ms pacing with identical localized system prompts and identical 120 ms tool fixtures. Response latency is measured via word-level forced alignment from the caller's last spoken word end to the agent's first spoken reply word start (p50 / p90, lower is better). Audio quality is measured with DNSMOS OVRL (1 to 5, higher is better).
| Cohort slice | Trelis pass | Trelis reply p50 / p90 (↓) | Trelis DNSMOS | Gemini 3.8 Live pass | Gemini reply p50 / p90 (↓) | Gemini DNSMOS |
|---|---|---|---|---|---|---|
| English overall (8 calls: 3 direct + 5 tool) | 8 / 8 (100%) | 934 ms / 2,530 ms | 3.12 | 8 / 8 (100%) | 1,748 ms / 2,535 ms | 3.40 |
| English direct conversational turns (3 calls) | 3 / 3 (100%) | 713 ms / 2,017 ms | 3.26 | 3 / 3 (100%) | 1,410 ms / 1,726 ms | 3.45 |
| English async tool calls (5 calls, incl. 2-tool parallel) | 5 / 5 (100%) | 1,768 ms / 2,530 ms | 3.03 | 5 / 5 (100%) | 2,111 ms / 2,535 ms | 3.38 |
| Non-English EU6 tool calls (ES, FR, DE, IT, PT, NL) | 4 / 6 (66.7%) | 2,249 ms / 4,155 ms | 2.73 | 6 / 6 (100%) | 1,978 ms / 2,043 ms | 3.33 |
| All 14 live calls combined | 12 / 14 (85.7%) | 1,768 ms / 2,831 ms | 2.95 | 14 / 14 (100%) | 1,947 ms / 2,284 ms | 3.37 |
6 mid-sentence caller interruptions (pivoting to a new tool lookup while the agent is speaking) and 4 short backchannels (“yeah”, “uh-huh”, “mm-hmm”, “okay”). Clear latency is measured from the caller's forced-aligned first word onset to audio interruption. Semantic word-based yielding avoids cutting off the agent on half of short backchannels, where pure acoustic VAD triggers a false interrupt every time.
| System | Interruption stop recall | Post-barge-in uptake | Clear latency p50 | Backchannels non-interrupted (↑) |
|---|---|---|---|---|
| Trelis duplex-speech-1 ($0.90 / connected hr) | 5 / 6 | 5 / 6 | 1,799 ms (semantic word yield) | 2 / 4 (50%) |
| Google Gemini 3.8 Live (Puck) | 6 / 6 | 6 / 6 | 73 ms (acoustic VAD cut) | 0 / 4 (0%) |
import asyncio, json, os, websockets
async def main():
url = (
"wss://api.trelis.com/v1/duplex/speech"
"?input_encoding=pcm_s16le&input_sample_rate=16000"
"&output_sample_rate=24000&output_audio_encoding=binary"
)
headers = {"Authorization": f"Bearer {os.environ['TRELIS_API_KEY']}"}
async with websockets.connect(url, additional_headers=headers) as ws:
print(json.loads(await ws.recv())) # ready
await ws.send(json.dumps({
"type": "session.start",
"system_prompt": "You are a concise multilingual phone support agent.",
"tools": [
{
"type": "function",
"function": {
"name": "lookup_order",
"description": "Look up customer order status and ETA.",
"parameters": {
"type": "object",
"properties": {"order_id": {"type": "string"}},
"required": ["order_id"],
},
},
}
],
}))
print(json.loads(await ws.recv())) # session.started
async def send_mic():
# Stream 80 ms chunks of 16 kHz mono PCM16 audio as binary frames.
for _ in range(25):
await ws.send(bytes(1280 * 2))
await asyncio.sleep(0.08)
await ws.send(json.dumps({"type": "end"}))
async def recv_events():
async for msg in ws:
if isinstance(msg, bytes):
# Play 24 kHz mono PCM16 audio bytes continuously.
continue
ev = json.loads(msg)
if ev["type"] == "agent.speech.pause" and ev.get("reason") == "barge_in":
# The duplex model yielded to the caller; let the short committed tail finish naturally.
print("Agent yielded to caller")
elif ev["type"] == "agent.tool_call":
await ws.send(json.dumps({
"type": "tool.result",
"call_id": ev["call_id"],
"content": {"order_id": "B42", "status": "out_for_delivery", "eta": "3pm today"},
}))
elif ev["type"] == "done":
print("Session billed:", ev)
break
await asyncio.gather(send_mic(), recv_events())
asyncio.run(main())