Publishing and Receiving Audio
You can publish audio, receive translated audio, and control the translation through either transport:
- WebRTC — best for client applications (browsers, mobile apps). Handled by LiveKit.
- WebSockets — convenient for server-side integrations. Authenticate with your API Key directly — see Translation management API for the connection details.
For WebRTC (or if you manage sessions yourself), start a streaming session first — Palabra returns two URLs and a JWT access token:
| Purpose | Field | Typical value |
|---|---|---|
| WebRTC (audio/control) | webrtc_url | https://<STREAMING_SERVER>.palabra.ai/livekit/ |
| WebSocket (audio/control) | ws_url | wss://<STREAMING_SERVER>.palabra.ai/streaming-api/v1/speech-to-speech/stream |
| Authentication | publisher | eyJhbGciOiJIUzI1NiIsInR5cCI6… |
format / sample_rate / channels declared in your set_task command.Using the WebRTC Transport
Use any LiveKit client library to publish your audio track, then create a translation task using the Translation management API. Palabra will publish a translated audio track for each target language.
- LiveKit Python SDK
- LiveKit Golang SDK
- LiveKit JS SDK
- See other SDKs here.
Code Examples
See the Quick Start Guide for code examples of publishing original audio (Step 4) and receiving translated audio (Step 5).
Using the WebSocket Transport
Connect to the WebSocket endpoint using your API Key (or to ws_url with a session publisher token — see Translation management API), create a translation task, then start sending and receiving audio chunks as described below.
Publishing
Send base64-encoded audio chunks over the WebSocket. The chunks must match the format, sample_rate, and channels declared in your set_task command. The optimal chunk length is 320 ms.
Message format example:
{
"message_type": "input_audio_data",
"data": {
"data": "base64 encoded data"
}
}
Receiving
Palabra sends TTS audio chunks as output_audio_data messages over the same WebSocket connection. The chunks are base64-encoded; the default format is 24 kHz 16-bit mono PCM (can be changed with the set_task command).
Message format example:
{
"message_type": "output_audio_data",
"data": {
"transcription_id": "190983855fe3404e",
"language": "es",
"last_chunk": false,
"data": "base64 string"
}
}