able-jackal-84140
10/03/2025, 11:14 AMtall-airline-16756
10/03/2025, 11:14 AMtall-airline-16756
10/03/2025, 11:15 AMRoomIO system, which smoothly manages the media streams between the agent and everyone else.
By default, the agent hears all participant audio streams, but if you want to change that, you can easily configure it using RoomInputOptions to decide which audio to receive. Likewise, if the agent needs to send audio back into the room, that’s handled through RoomOutputOptions.
If you'd like, I’m here to help with more detailed steps or examples, especially if you're working on setting up audio input/output or integrating with avatar-based systems. Just let me know, and we’ll figure it out together!
Sources: Building voice agents | LiveKit Docs | basics/playing_audio.py | livekit-plugins/livekit-plugins-tavus/livekit/plugins/tavus/avatar.py | Web and mobile frontends | LiveKit Docs | LiveKit Docsable-jackal-84140
10/03/2025, 11:27 AMtall-airline-16756
10/03/2025, 11:27 AMfrom livekit.agents.voice.room_io import RoomInputOptions, RoomOutputOptions
# Configure audio input options
input_options = RoomInputOptions(
audio_enabled=True, # Enable audio input
text_enabled=True, # Enable text input (optional)
audio_sample_rate=24000,
audio_num_channels=1
)
# Configure audio output options
output_options = RoomOutputOptions(
audio_enabled=True, # Enable audio output
transcription_enabled=True,
audio_sample_rate=24000,
audio_num_channels=1
)
# Start the agent session with the configured options
await session.start(
agent=agent,
room=ctx.room,
room_input_options=input_options,
room_output_options=output_options
)
# Example: Agent speaking in the room
await session.say("Hello, I can speak now!", allow_interruptions=False)
This example shows how you can set up the agent to both receive audio from the room and send audio back into it. If you have any questions or would like me to walk you through any part of this, just let me know—I’m here to help!able-jackal-84140
10/03/2025, 12:00 PMtall-airline-16756
10/03/2025, 12:01 PMfrom livekit import api
req = api.RoomCompositeEgressRequest(
room_name="my-room",
layout="speaker",
preset=api.EncodingOptionsPreset.H264_720P_30,
audio_only=False,
segment_outputs=[api.SegmentedFileOutput(
filename_prefix="my-output",
playlist_name="my-playlist.m3u8",
segment_duration=5,
gcp=api.GCPUpload(
credentials="<your-gcp-credentials-json>",
bucket="your-bucket-name",
),
)],
)
lkapi = api.LiveKitAPI()
res = await lkapi.egress.start_room_composite_egress(req)
This will capture all the audio and video in the room and save it to your chosen cloud destination like S3 or GCP. It's a great way to get a full recording effortlessly.
2. Real-Time Audio Interception
If you're looking to process audio selectively or save shorter snippets, you can use rtc.AudioStream to access raw audio frames as they come in. Here's how you might do that:
from livekit import rtc
from livekit.agents import AudioStream, combine_audio_frames
buffer = []
async def on_track_subscribed(track: rtc.Track, *_):
if track.kind == rtc.TrackKind.KIND_AUDIO:
stream = rtc.AudioStream(track)
async for frame in stream:
buffer.append(frame)
# Stop after ~7 seconds
if frame.timestamp > 7_000:
break
# Export as WAV bytes
combined = combine_audio_frames(buffer)
wav_bytes = combined.to_wav_bytes()
# Save to file or send to another processor
This method is perfect if you want to handle audio in real-time or focus on specific parts. Feel free to ask if you'd like me to walk you through this in more detail or provide additional examples!
Sources: docs/index.yaml | Session recording and transcripts | LiveKit Docs | Capturing the First Few Seconds of a Call for Processing | Processing raw media tracks | LiveKit Docs