hundreds-vase-7385
12/10/2025, 12:04 PMtall-airline-16756
12/10/2025, 12:04 PMtall-airline-16756
12/10/2025, 12:05 PMAudioSource and LocalAudioTrack for each say call (set sample rate/channels appropriate for your TTS).
2. Publish that track with publish_track (this creates a new TrackPublication with its own sid).
3. Stream TTS audio frames into the AudioSource (e.g., using the TTS plugin's streaming frames or converting PCM to AudioFrame).
4. Optionally unpublish the track when the utterance finishes (so clients can clean up).
Notes the client will use:
• Each publication has a unique `sid`; clients can subscribe/unsubscribe per-publication.
• Listen for track-published events and inspect the publication sid or metadata to decide subscription.
If you’d like, tell me:
• which agent SDK/language you’re using (Python, JS, or other), and
• which TTS engine/plugin you plan to use
and I’ll provide a short, concrete code example for that stack.
Sources: Subscribing to tracks | LiveKit docshundreds-vase-7385
12/10/2025, 12:06 PMtall-airline-16756
12/10/2025, 12:06 PMsid, name, or metadata to decide which tracks to subscribe to.
2) Minimal JS example (Agent SDK + ElevenLabs)
import * as livekitServer from 'livekit-server-sdk'; // livekit rtc objects
import * as elevenlabs from '@livekit/agents-plugin-elevenlabs';
import { v4 as uuidv4 } from 'uuid';
async function publishUtterance(ctx: any, text: string) {
const tts = new elevenlabs.TTS({
voice: 'YOUR_ELEVENLABS_VOICE_ID',
model: 'eleven_multilingual_v2',
});
// create a unique name for this utterance
const trackName = `agent-utterance-${Date.now()}-${uuidv4()}`;
// create AudioSource and LocalAudioTrack
const sampleRate = 24000;
const channels = 1;
const source = new livekitServer.AudioSource(sampleRate, channels);
const track = new livekitServer.LocalAudioTrack(trackName, source);
// publish the track (creates new TrackPublication)
const publication = await ctx.room.localParticipant.publishTrack(track, {
name: trackName,
source: livekitServer.Track.Source.Microphone,
});
// stream TTS audio frames and push to source
for await (const chunk of tts.synthesize(text)) {
// chunk.frame should be an AudioFrame compatible with AudioSource
await source.captureFrame(chunk.frame);
}
// optional: unpublish/stop after finished (client can still hold onto publication until removed)
// await ctx.room.localParticipant.unpublishTrack(track);
}
3) Tips
• Use unique names or metadata (timestamp/UUID) so clients can identify each utterance.
• If you want published tracks short-lived, unpublish after streaming; otherwise keep them and let clients unsubscribe.
• Ensure the ElevenLabs plugin yields AudioFrame objects (or convert PCM to AudioFrame) before calling captureFrame.
If you want, I can:
• Provide a ready-to-run example adapted for your exact agent scaffolding,
• Show how clients can filter/subscribe to publications by name or metadata. Which would you prefer? Sources: ElevenLabs TTS plugin guide | LiveKit Docs | Camera & microphone | LiveKit docs