I have a question: Without egress, is it possible ...
# ask-ai
b
I have a question: Without egress, is it possible to record the audio in the room using our custom code on the worker side, even if we are using LiveKit Cloud?
t
Thanks for reaching out, Yethu. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
It is possible to record audio from a LiveKit Cloud room using your own custom code on the worker side, without using the egress feature. This can be done by connecting to the room as a participant with the LiveKit SDK, subscribing to the audio tracks, and then processing the audio frames directly in your code. For example: • Connect to the room using the SDK (such as Rust or Node.js) • Subscribe to audio tracks by listening for track subscription events • Create an audio stream from the subscribed track • Process the audio frames as they arrive • Write the audio data to your preferred format (such as WAV files) This method gives you full control over the recording process and allows for custom audio processing or storage, all without relying on the egress service. Let me know if you need a specific code example or further details for a particular SDK or use case. Sources: packages/livekit-server-sdk/src/EgressClient.ts
b
I need to see I can record the user audio but the Ai recording that is TTS
t
Hey there! Let me break down how you can capture audio from just one specific participant - super handy when you want to focus on a particular person's sound. I've got two awesome approaches for you: • Participant Egress: Think of this like a personal audio spotlight. You can record audio directly from a specific participant by their unique identity. It's smart too - it'll automatically handle things like muting or unpublishing, so you get exactly what you want. • TrackComposite Egress: This is for when you want more of a custom audio mixing board. You can pick and choose specific audio tracks by their track IDs. Perfect if you want to include or exclude certain tracks, like filtering out AI voices. Pro tip: When setting up your recording, use participant identity or attributes to easily tell the difference between real human users and AI voices. Need a code example or want me to dive deeper into how this works with a specific SDK? Just ask - I'm here to help! Sources: packages/livekit-server-sdk/src/EgressClient.ts | lib/livekit/egress_service_client.rb | Inside a session | LiveKit Docs | Recording Participants | LiveKit Docs
b
show me the SDK how I can record the TTS audio from livekit
t
Hey there! Want to capture audio from a specific AI TTS participant in LiveKit? No worries, the Participant Egress feature has got you covered. It's super easy to record just the audio from the participant matching your TTS agent's identity. Let me walk you through a Python example using the LiveKit SDK:
Copy code
from livekit import api

async def entrypoint(ctx):
    req = api.ParticipantEgressRequest(
        room_name=ctx.room.name,
        identity="your-tts-agent-identity",  # The TTS participant's identity
        audio_only=True,
        file_outputs=[api.EncodedFileOutput(
            file_type=api.EncodedFileType.OGG,
            filepath="recordings/tts-agent-audio.ogg",
            # Optionally configure S3 upload here
        )],
    )

    lkapi = api.LiveKitAPI()
    res = await lkapi.egress.start_participant_egress(req)
    await lkapi.aclose()
• Just swap out
your-tts-agent-identity
with your TTS participant's actual identity. • This clever method will record only the audio from your TTS agent, leaving other participants' audio untouched. • Feel free to customize the output file format and location to suit your needs. This approach makes capturing your TTS audio stream a breeze. Need an example for a different SDK or want to record using track IDs? I'm here to help – just give me a shout! Sources: livekit-agents/livekit/agents/voice/room_io/_output.py | Recording participants | LiveKit Docs | How to set a fixed participant for agent audio processing