Skip to main content
One Python script that creates a call, streams your microphone to Pearl and plays its voice through your speakers. Press Ctrl+C to hang up.
1

Install

Python 3.11 or later, then:
av codes the audio in Opus, and includes the codec. On Linux, also install PortAudio: sudo apt install libportaudio2. On macOS and Windows it comes with sounddevice.
2

Save the script

Save it as pearl_quickstart.py.
pearl_quickstart.py
3

Run it and talk

Use headphones: a terminal has no echo cancellation, and Pearl would hear itself through your speakers.
Your <AccountId>:<SecretKey> is on the API Access page of your workspace settings (API Authorization). Your <pearlId> is on your Pearl’s overview page, in the Settings popover. If your Pearl’s opening sentence uses variables, put them in CALL_DATA first: the script stops with the reason when one is missing.Pearl greets you; answer it. On macOS, allow the terminal to use the microphone the first time.
Output
The call is in your call history with its transcript and recording, like any other call of your Pearl.

How the script works

  • The order: create the token, open url?token=…, wait for ready, then stream.
  • The pacing: the sound card hands over 20 ms of the microphone every 20 ms, silence included, which is exactly what Pearl expects.
  • The playback: Pearl’s frames go through an 80 ms buffer, which absorbs network jitter.
  • The ending: Ctrl+C sends hangup, answered by ended. If Pearl ends the call first, the script prints its ended and stops.
  • The codec: the call is in opus_24000. Each 20 ms of the microphone is coded to one Opus packet before it is sent, and each packet from Pearl is decoded before it is played, at 48 kHz, the rate the Opus decoder returns.

Next steps

Browser App

The same conversation from a web page.

Stream WebSocket

Every message, audio format, event and limit.