How would I capture audio media data and save it t...
# ask-ai
b
How would I capture audio media data and save it to S3 on self hosted livekit?
t
Thanks — I’m responding to your question about how to capture audio from a self‑hosted LiveKit deployment and save it to S3. Overview: Use LiveKit Egress (the Egress service) to record/export audio from rooms or individual tracks and upload the resulting file to Amazon S3. Track Egress is the most efficient option for per-participant raw audio (Opus/OGG). You can start egress from a Server SDK call and automate it with webhooks. Steps to implement 1. Ensure Egress is running and connected • Deploy the LiveKit Egress service in your self‑hosted environment and make sure it can talk to your LiveKit server (Egress uses Redis Pub/Sub to coordinate with LiveKit). • Confirm Egress has network access to your S3 bucket and permissions to write. 1. Choose egress type • Track Egress: exports a single participant’s audio track (Opus in OGG). Best for per-agent audio capture. • Room Composite / Track Composite: use if you need mixed room audio or synchronized audio+video. 1. Start egress from your backend (Server SDK) • Use the LiveKit Server SDK (Go, Node, Python, etc.) to start egress programmatically when you want to record (on demand or triggered by events). • Provide S3 output in the egress request (bucket, region, credentials OR use assume-role). Example (conceptual Go-style payload for Track Egress to S3):
Copy code
StartTrackEgress({
  RoomName: "your-room",
  TrackId: "participant-audio-track-id",
  Output: {
    File: {
      FileType: "OGG",
      Filepath: "recordings/agent-audio.ogg",
      Output: {
        S3: {
          AccessKey: "AWS_ACCESS_KEY",
          Secret: "AWS_SECRET",
          Bucket: "your-bucket",
          Region: "us-west-2"
        }
      }
    }
  }
})
• You obtain
TrackId
from the room/participant list or from Webhook events (participant joined/published). 1. Automate with webhooks • Use LiveKit webhooks to trigger egress: e.g., start egress when a room starts or when a participant begins speaking, and stop on
egress_ended
or
room_ended
. • Listen for
egress_started
and
egress_ended
events to track status and errors. 1. Alternative: WebSocket forwarding for real-time processing • If you need real‑time processing (transcription, VAD, custom transforms) before storing, configure egress to stream raw PCM audio to a WebSocket endpoint. • Your WebSocket server can process audio frames and then upload results or the original file to S3. 1. Secure credentials • For production, prefer IAM roles (AssumeRole) instead of storing long‑lived AWS keys in config. Egress supports assuming a role (configure the assume role fields) so LiveKit can write to S3 securely. 1. Post-processing and correlation • Use egress metadata (timestamps, participant IDs) and webhooks to correlate stored audio with sessions/agents. • Optionally combine audio files with transcripts or tracing metadata in your own pipeline. If you want, tell me: • which Server SDK you use (Go / Node / Python), and • whether you want per-track recordings or full-room recordings, and • whether you prefer to use AWS access keys or AssumeRole for S3 access, and I’ll provide a concrete code snippet and a webhook flow you can drop into your self‑hosted deployment. Sources: Universal Egress | Universal Egress | server-sdk-js | livekit/livekit_composite | DeepWiki | Universal Egress