Skip to main content
The Realtime API gives your app a live, speech-to-speech conversation with your Pearl: you stream the end user’s voice in and play Pearl’s voice back as it speaks. It is the same Pearl as on your phone numbers, with the same flow, call history, webhooks, recordings and billing. Only the start differs: your app starts the call through the API, with no phone number.

Before you start

  • A voice Pearl that is active. The call runs its published version.
  • Its Pearl ID: on your Pearl’s overview page, in the Settings popover.
  • An API key, or an OAuth app with the pearls:websocket scope (Make Realtime API calls in the platform). See API Authorization.
  • One of the two audio formats, the same in both directions:

Connect

1

Create the call

From your backend, call Create Call. It returns the url to open and a ticket valid for 60 seconds.
endUserId is your own id for the person on the call, such as a customer id: send the same value for the same person every time.
2

Open the WebSocket

Open the url with the ticket, within 60 seconds. Pearl sends ready, then you stream.
Your API key stays on your backend. A browser or an app gets only the url and the ticket, which open this one call, once.

Stream audio

  • Audio is binary, in both directions: raw bytes in the call’s format, with no base64 and no JSON.
  • Send one 20 ms frame every 20 ms, in real time, for the whole call. When the end user is quiet or muted, send silence, not nothing.
  • Pearl sends one 20 ms frame every 20 ms too, with silence while it listens. Play the frames through a small jitter buffer of 60 to 100 ms.
  • Interruptions need no code. When the end user talks over Pearl, it stops speaking and the next frames are already silence: there is nothing to clear on your side.

Events

Text messages are JSON events. Pearl sends three: To hang up, send {"type":"hangup"}. After the call, the call history and the webhooks show it with channel: "websocket".

Errors and limits

A message is at most 16 KB. Stream Call has every message, end reason and limit.

Examples

Quickstart

Talk to your Pearl from your terminal, with your microphone.

Browser App

A web page with the microphone and Pearl’s voice.