WebSocket Integration
Integrate with your server via direct WebSocket connections.
The Ultravox API allows you to create AI-powered voice applications that can interact through various protocols:
- WebRTC → Default protocol for browser and mobile applications.
- Regular Phone Numbers → Connect Ultravox to phone calls you make or receive (via Telnxy, Twilio, or Plivo).
- WebSockets → Direct server-to-server integration.
For more information about WebRTC and Phone, consult the Telephony guide.
WebsSocket connections are designed for server-to-server communication. For browser or mobile applications, use our client SDKs with WebRTC for optimal performance. WebSocket connections over TCP can experience audio blocking and ordering constraints that make them unsuitable for direct client use.
Creating a WebSocket Call
Creating a WebSocket-based call with Ultravox requires setting medium
to serverWebSocket
and passing in parameters for sample rates and buffer size.
- inputSampleRate (required): Sample rate for input (user) audio (e.g., 48000).
- outputSampleRate (optional): Sample rate for output (agent) audio (defaults to inputSampleRate).
- clientBufferSizeMs (optional): Size of the client-side audio buffer in milliseconds. Smaller buffers allow for faster interruptions but may cause audio underflow if network latency fluctuates too greatly. For the best of both worlds, set this to some large value (e.g. 30000) and implement support for PlaybackClearBuffer messages. (Defaults to 60).
See Data Messages for more information on all available messages.
WebSocket connections use the same message format as WebRTC data channels. See our Data Messages documentation for detailed message specifications.