how to use RecorderIO
# ask-ai
a
how to use RecorderIO
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.
I'm happy to help you get started with
RecorderIO
in LiveKit! Here’s a simple step-by-step guide to make things easier: 1. Initialize `RecorderIO`: Begin by creating an instance with your
AgentSession
. You can also set a sample rate if you want.
recorder_io = RecorderIO(agent_session=agent_session, sample_rate=48000)
2. Record Input and Output: Wrap your audio streams using
record_input()
and
record_output()
.
Copy code
input_audio = recorder_io.record_input(your_audio_input)
output_audio = recorder_io.record_output(your_audio_output)
3. Start Recording: When you’re ready, call
start()
with the path where you want to save the recording.
await recorder_io.start(output_path="output_recording.ogg")
4. Stop Recording: Finally, use
aclose()
to stop and properly finalize your recording.
await recorder_io.aclose()
The recording will be saved as a stereo OGG/Opus file, with the input audio on the left channel and the output on the right. Just a quick tip: make sure to call both
record_input()
and
record_output()
before starting the recorder to avoid any hiccups. If you have any questions or need a hand with anything else, please don’t hesitate to ask. I’m here to help! Sources: livekit-agents/livekit/agents/voice/recorder_io/__init__.py | Capturing the First Few Seconds of a Call for Processing
a
how to use recorderIO with agent session?
t
To get started with
RecorderIO
alongside an
AgentSession
, here’s a simple step-by-step guide to help you out: 1. Initialize `RecorderIO`: Just pass the
AgentSession
into the
RecorderIO
constructor.
recorder_io = RecorderIO(agent_session=agent_session, sample_rate=48000)
2. Wrap Input and Output Streams: Use
record_input()
and
record_output()
to wrap your agent’s audio streams.
Copy code
input_audio = recorder_io.record_input(agent_audio_input)
output_audio = recorder_io.record_output(agent_audio_output)
3. Start Recording: Kick off the recording by specifying where you want to save the output file.
await recorder_io.start(output_path="output_recording.ogg")
4. Stop Recording: When you’re done, use
aclose()
to properly finalize and stop the recording.
await recorder_io.aclose()
Just a quick tip: make sure you call both
record_input()
and
record_output()
before starting the recorder to avoid any hiccups. Your recording will be saved as a stereo OGG/Opus file, with the input on the left channel and the output on the right. If you have any questions or need more examples, feel free to ask—I’m here to help! Sources: livekit-agents/livekit/agents/voice/recorder_io/__init__.py | Capturing the First Few Seconds of a Call for Processing | Session recording and transcripts | LiveKit Docs