fast-gpu-71889
02/24/2025, 7:22 PMgray-monkey-83525
02/24/2025, 7:22 PMfast-gpu-71889
02/24/2025, 7:23 PMgray-monkey-83525
02/24/2025, 7:23 PMimport asyncio
from livekit import EgressClient, EgressOptions, EncodedFileOutput, S3Upload
async def start_audio_egress(room_name: str, participant_identity: str):
# Configure the output for the egress
file_output = EncodedFileOutput(
filepath=f"{room_name}/{participant_identity}/audio_recording.mp3",
s3=S3Upload(
bucket="your_bucket_name",
region="your_region_name",
access_key="your_access_key",
secret="your_secret",
force_path_style=True,
),
)
# Create the egress request
egress_options = EgressOptions(
room_name=room_name,
identity=participant_identity,
file_outputs=[file_output]
)
# Initialize the EgressClient
egress_client = EgressClient(api_key="your_api_key", api_secret="your_api_secret")
try:
# Start the egress
egress_info = await egress_client.start_participant_egress(egress_options)
print(f"Egress started: {egress_info.egress_id}")
except Exception as e:
print(f"Failed to start egress: {e}")
# Example usage
asyncio.run(start_audio_egress("my_room", "participant_identity"))
This code sets up an egress to record a participant's audio track and store it in an S3 bucket. Make sure to replace placeholders like your_bucket_name
, your_region_name
, your_access_key
, your_secret
, your_api_key
, and your_api_secret
with your actual credentials.
Would you like more details on any specific part of this setup?
Sources:
- https://livekit-users.slack.com/archives/C07FVFGAUKX/p1733152587.089089
- https://livekit-users.slack.com/archives/C07FVFARRK7/p1730759958.958929 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.fast-gpu-71889
02/24/2025, 7:31 PMgray-monkey-83525
02/24/2025, 7:31 PMEgressOptions
class is not explicitly mentioned in the provided data sources. Instead, you should use the ParticipantEgressRequest
class to configure and start participant egress. Here's an updated code snippet using the correct class:
import asyncio
from livekit import api
async def start_audio_egress(room_name: str, participant_identity: str, lkapi):
req = api.ParticipantEgressRequest(
room_name=room_name,
identity=participant_identity,
file_outputs=[
api.EncodedFileOutput(
filepath=f"{room_name}/{participant_identity}/audio_recording.mp4",
s3=api.S3Upload(
bucket="your_bucket_name",
region="your_region_name",
access_key="your_access_key",
secret="your_secret",
force_path_style=True,
),
)
]
)
try:
egress_info = await lkapi.egress.start_participant_egress(req)
print(f"Egress started: {egress_info.egress_id}")
except Exception as e:
print(f"Failed to start egress: {e}")
# Example usage
async def main():
lkapi = api.LiveKitAPI(api_key="your_api_key", api_secret="your_api_secret")
await start_audio_egress("my_room", "participant_identity", lkapi)
asyncio.run(main())
This code uses ParticipantEgressRequest
to set up the egress for recording audio. Ensure you replace the placeholders with your actual credentials and configuration details.
Would you like more information on setting up or using this code?
Sources:
- https://livekit-users.slack.com/archives/C07FY8WHGPM/p1728856136.961559 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.fast-gpu-71889
02/24/2025, 7:34 PMgray-monkey-83525
02/24/2025, 7:34 PMaudio_only
parameter to True
in your egress request. Here's how you can modify the code to ensure that only audio is recorded:
import asyncio
from livekit import api
async def start_audio_egress(room_name: str, participant_identity: str, lkapi):
req = api.ParticipantEgressRequest(
room_name=room_name,
identity=participant_identity,
audio_only=True, # Ensure only audio is recorded
file_outputs=[
api.EncodedFileOutput(
filepath=f"{room_name}/{participant_identity}/audio_recording.m4a",
s3=api.S3Upload(
bucket="your_bucket_name",
region="your_region_name",
access_key="your_access_key",
secret="your_secret",
force_path_style=True,
),
)
]
)
try:
egress_info = await lkapi.egress.start_participant_egress(req)
print(f"Egress started: {egress_info.egress_id}")
except Exception as e:
print(f"Failed to start egress: {e}")
# Example usage
async def main():
lkapi = api.LiveKitAPI(api_key="your_api_key", api_secret="your_api_secret")
await start_audio_egress("my_room", "participant_identity", lkapi)
asyncio.run(main())
This code snippet sets audio_only=True
to ensure that only the audio track is recorded. The output file is saved with an .m4a
extension, which is suitable for audio-only files.
Would you like more details on any specific part of this setup?
Sources:
- https://livekit-users.slack.com/archives/C07FVFARRK7/p1730759958.958929 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.