able-jackal-84140
10/03/2025, 9:09 AMtall-airline-16756
10/03/2025, 9:09 AMtall-airline-16756
10/03/2025, 9:09 AMRecorderIO class in LiveKit is a wonderful tool designed to help you capture full-session audio recordings within LiveKit Agents (Python). It neatly records both the audio input (your user's voice) and the output (the agent's response) into a perfectly synchronized audio file. Let me walk you through how to use it:
1. Initialize RecorderIO: First, create an instance using your running `AgentSession`:
recorder_io = RecorderIO(agent_session=agent_session)
2. Wrap Audio Streams: Then, use record_input() and record_output() to wrap your input and output audio streams:
self._input_audio = recorder_io.record_input(self._input_audio)
self._output_audio = recorder_io.record_output(self._output_audio)
3. Start Recording: When you're ready, start the recording by specifying an output file path:
await recorder_io.start(output_path="my_recording.ogg")
4. Stop Recording: Finally, wrap things up by stopping the recording with:
await recorder_io.aclose()
The resulting file will be in OGG format with the OPUS codec, beautifully mixing input (left channel) and output (right channel) as a stereo track.
If you’d like any help implementing this or want to explore other options like Egress for room-level recording, please don’t hesitate to reach out—I’m here to help!
Sources: livekit-agents/livekit/agents/voice/recorder_io/__init__.py | src/room/track/record.ts | Capturing the First Few Seconds of a Call for Processing | Session recording and transcripts | LiveKit Docsable-jackal-84140
10/03/2025, 10:28 AMtall-airline-16756
10/03/2025, 10:29 AMRecorderIO with your agent:
1. Initialize RecorderIO: First, create an instance of RecorderIO and pass your active AgentSession to it:
from livekit import RecorderIO
# Assuming you have an active AgentSession
recorder_io = RecorderIO(agent_session=agent_session)
2. Wrap Input and Output Streams: Next, wrap your agent's input and output audio streams so they can be recorded:
# Wrap the input and output audio streams
self._input_audio = recorder_io.record_input(self._input_audio)
self._output_audio = recorder_io.record_output(self._output_audio)
3. Start Recording: To begin recording, specify where you'd like to save the file:
import datetime
# Generate a timestamped filename
filename = f"recording_{datetime.datetime.now().strftime('%Y-%m-%d_%H-%M')}.ogg"
await recorder_io.start(output_path=filename)
4. Stop Recording: When your session wraps up, stop the recording to finalize the file:
await recorder_io.aclose()
5. Link to Shutdown: If you'd like, you can connect the recorder's closure with your agent's shutdown process:
job_ctx.add_shutdown_callback(recorder_io.aclose)
This way, your entire session will be recorded and saved as an OGG audio file. If you have any questions or need a hand with any step, just let me know—I’m here to help!able-jackal-84140
10/03/2025, 10:30 AMtall-airline-16756
10/03/2025, 10:30 AMrecord_input() and record_output() methods from RecorderIO to wrap these streams. For example:
# Assuming self._input_audio and self._output_audio are your audio streams
self._input_audio = recorder_io.record_input(self._input_audio)
self._output_audio = recorder_io.record_output(self._output_audio)
3. Timing: Just make sure to do this wrapping before the streams are actively used for processing audio. Usually, this happens during the initialization phase of your agent session.
If you’d like, feel free to share more details about your agent’s setup—I’d be happy to provide a more personalized example to guide you further!able-jackal-84140
10/03/2025, 10:31 AMtall-airline-16756
10/03/2025, 10:32 AMRecorderIO with your agent and access the audio streams:
1. Set Up the Agent: Let's start by assuming you already have an agent session running, and the audio streams for input and output are ready to go.
2. Initialize RecorderIO: Next, create an instance of RecorderIO and pass your agent session to it:
from livekit import RecorderIO
# Initialize RecorderIO with the agent session
recorder_io = RecorderIO(agent_session=agent_session)
3. Access and Wrap Audio Streams: Now, take your agent's audio streams (like self._input_audio and self._output_audio) and wrap them using record_input() and `record_output()`:
# Wrap the input and output audio streams
self._input_audio = recorder_io.record_input(self._input_audio)
self._output_audio = recorder_io.record_output(self._output_audio)
4. Start Recording: You’re all set to start recording! Just specify where you'd like to save the file:
import datetime
# Generate a timestamped filename
filename = f"recording_{datetime.datetime.now().strftime('%Y-%m-%d_%H-%M')}.ogg"
await recorder_io.start(output_path=filename)
5. Stop Recording: When your session wraps up, simply stop the recording to finalize the file:
await recorder_io.aclose()
Just a quick note: self._input_audio and self._output_audio are placeholders for the audio streams your agent uses. If your setup involves different methods or libraries for handling audio, you might need to tweak this example a bit to fit your needs. Feel free to reach out if you’d like me to clarify anything or help further!able-jackal-84140
10/03/2025, 10:46 AM# av.error.MemoryError: [Errno 12] Cannot allocate memory when using RecorderIOtall-airline-16756
10/03/2025, 10:46 AM