How to create an egress service for locally saving...
# ask-ai
a
How to create an egress service for locally saving the audio?
t
Thanks for reaching out, Aditya. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks for reaching out! To help you better, could you please let me know if you're planning to use LiveKit's built-in egress APIs, or if you're thinking about creating a custom solution? Also, it would be great to know if you're working with a particular programming language or framework. I'm here to assist you every step of the way!
a
If I can use inbuilt egress service that would be great. Or if custom solution is required that is also fine by me. I am using python currently
t
I'm happy to help you save audio locally using LiveKit's built-in egress service! Here are a few ways you can do this: • WebSocket Streaming: You can stream raw PCM audio to a local WebSocket server and save it as a WAV file. This method works great if you want to save audio in real-time. If you'd like, I can share a Python example to get you started. • Mounted Volume: Another option is to use Docker to mount a local directory and set up LiveKit to save audio files directly there. • Local S3-Compatible Storage: You could also set up a local S3-compatible service like MinIO and configure LiveKit to save your audio files to that storage. Just a quick note: saving directly to a local file path without using Docker or a WebSocket server isn’t supported at the moment. Please let me know which option sounds best for you, and I’d be more than happy to guide you through the next steps or provide some examples! Sources: README.md | Track egress | LiveKit Docs
a
give me an exmaple fo docker to save the audio
t
I'd love to help you get started with using Docker to save audio locally with LiveKit! Here’s a simple step-by-step guide: 1. Run the LiveKit Egress Docker Container: Try running this command to start the LiveKit egress service with a mounted volume: `docker run --rm \ -e EGRESS_CONFIG_FILE=/out/config.yaml \ -v ~/livekit-egress:/out \ livekit/egress`What this does is mount your local directory
~/livekit-egress
to the container’s
/out
directory. Feel free to replace
~/livekit-egress
with any local path you prefer. 2. Configure the Egress Request: In your Python code, you’ll want to specify the file output path inside that mounted directory like this: `from livekit.api import LiveKitAPI from livekit.protocol.egress import TrackEgressRequest, DirectFileOutput api = LiveKitAPI() req = TrackEgressRequest( room_name="my-room", track_id="TR_audio_track_id", file=DirectFileOutput( filepath="/out/recording.ogg" # Matches the mounted path ) ) result = await api.egress.start_track_egress(req) print(f"Egress started: {result.egress_id}")`This setup will save your audio file as
recording.ogg
right in the
~/livekit-egress
folder on your computer. If you have any questions or want me to walk you through more examples, just let me know—I’m here to help!
a
I don't want to use websocket and docker. Is there any other method I can choose to save the audio?
t
If you’d rather not use WebSocket or Docker, no worries! You can easily set up a local S3-compatible storage service like MinIO. This way, you can save your audio files locally while still using LiveKit’s S3Upload configuration. 1. Install and Run MinIO: First, download and run MinIO on your local machine with this command: `docker run -p 9000:9000 -p 9001:9001 \ --name minio \ -e "MINIO_ROOT_USER=minioadmin" \ -e "MINIO_ROOT_PASSWORD=minioadmin" \ quay.io/minio/minio server /data --console-address ":9001"`This will start MinIO using the default credentials
minioadmin:minioadmin
and make it accessible at
http://localhost:9000
. 2. Configure LiveKit to Use MinIO: Next, in your Python code, you can set up the egress request to point to your MinIO endpoint like this: `from livekit.api import LiveKitAPI from livekit.protocol.egress import TrackEgressRequest, S3Upload api = LiveKitAPI() req = TrackEgressRequest( room_name="my-room", track_id="TR_audio_track_id", file=S3Upload( bucket="livekit-recordings", region="us-east-1", access_key="minioadmin", secret="minioadmin", endpoint="http://localhost:9000", filepath="recordings/audio.ogg" ) ) result = await api.egress.start_track_egress(req) print(f"Egress started: {result.egress_id}")`This setup will save your audio file to the
/data
directory in MinIO, which you can access right from your local machine. If you have any questions or want me to walk you through any part of this, just let me know—I’m here to help!
a
Like I said I don't want to use the egress service.
t
I don't have the answer you're looking for. You could also try asking your question: • in one of the other Slack channels or • to https://deepwiki.com/livekit/livekit_composite which is trained on all LiveKit source code If you find the answer, please post it here to help others!