<@U084APK40NS> I am using voice pipeline and want ...
# ask-ai
f
@millions-hair-24956 I am using voice pipeline and want to record stereo audio for voice call, please help with this
g
To record stereo audio for a voice call using LiveKit's voice pipeline, you can utilize the Participant Egress feature. This allows you to record individual participant tracks, including stereo audio, by specifying the participant's identity. According to the Recording Participants documentation, you can configure the Egress to focus on audio recording, ensuring that the audio is captured in stereo if the source supports it. Would you like more detailed guidance on setting up Participant Egress for stereo audio recording? Sources: - Recording Participants documentation 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.
f
@millions-hair-24956 can you please give me sample code for same
g
Certainly! Below is a sample code snippet to set up Participant Egress for recording stereo audio in a LiveKit room. This example assumes you have already set up your LiveKit server and have the necessary API keys.
Copy code
import 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.
f
there is no such EgressOptions class @millions-hair-24956
g
The
EgressOptions
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:
Copy code
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.
f
@millions-hair-24956 I want audio only file
g
To record an audio-only file using LiveKit's egress service, you can set the
audio_only
parameter to
True
in your egress request. Here's how you can modify the code to ensure that only audio is recorded:
Copy code
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.