Skip to main content

Broadcaster Captions

Text Captions are included by default for any Broadcast Task you have created - there is no need to specify any exact configuration in your create-broadcast request.

To fetch Captions in real-time you have to:

  • Connect to the Palabra Centrifuge server
  • Subscribe to the captions, using Broadcast ID

Example:

import { Centrifuge } from 'centrifuge';

const broadcastID = "<broadcast_id>";
const serverURL = `https://api.palabra.ai/broadcasts/${broadcastID}/subtitles`;

// Fetch Translation task's meta data by its broadcastID
const { data } = await axios.get(serverURL, {
headers: {
// Visit https://docs.palabra.ai/docs/auth/obtaining_api_keys
ClientID: "<PALABRA_API_CLIENT_ID>",
ClientSecret: "<PALABRA_API_CLIENT_SECRET>"
}
});

// Create the Centrifuge client insance
const centrifuge = new Centrifuge(data.websocket_url, { token: data.connection_token });

// Configure your subscription for the Centrifuge's data
const subscription = centrifuge.newSubscription(broadcastID, { token: data.subscription_token });

// Set up the `publication` event listener to handle the captions
subscription.on('publication', (ctx) => {
const { data } = ctx;
console.log('captions record', data); // Here is your captions message
});

// Init your subscription and connect the server
subscription.subscribe();
centrifuge.connect();