using Livekit JS SDK how would I read the incoming...
# ask-ai
c
using Livekit JS SDK how would I read the incoming TTS stream?
t
Thanks for reaching out, Guillaume. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
To read an incoming TTS (Text-to-Speech) stream using the LiveKit JS SDK, the TTS audio is delivered as a standard WebRTC audio track, which looks just like any other participant audio track unless you use metadata or signaling to label it. Here’s a friendly guide on how you can handle it: • Listen for the
trackPublished
event to know when an audio track is published:
Copy code
room.on('trackPublished', (trackPublication, participant) => {
  if (trackPublication.kind === 'audio') {
    trackPublication.on('subscribed', (track) => {
      console.log('Received audio track');
      // This is where you can work with the audio track
    });
  }
});
If you’d also like to get the text version of the TTS output, you can enable synchronized transcription forwarding. Just use
registerTextStreamHandler
to listen for text streams on the
lk.transcription
topic:
Copy code
room.getLocalParticipant().registerTextStreamHandler('lk.transcription', async (reader) => {
  for await (const text of reader) {
    console.log('Agent is speaking:', text);
    // You can update your UI with captions or subtitles here
  }
});
Please feel free to reach out if you’d like me to walk you through any part of this or if you have any other questions—I’m here to help! Sources: agents/src/voice/agent.ts | Voice Assistant Applications | livekit/livekit_composite | DeepWiki | Text and transcriptions | LiveKit Docs