able-jackal-84140
10/03/2025, 7:14 AMtall-airline-16756
10/03/2025, 7:14 AMtall-airline-16756
10/03/2025, 7:15 AMWavWriter to save audio as a WAV file.
◦ Swift SDK: AudioManager.shared is great for starting local recordings and saving audio buffers.
◦ Android SDK: Using MediaCodec and MediaMuxer can help you save audio and video right on your device.
◦ Node.js SDK: You can use AudioStream to write audio frames directly to a WAV file.
• Using Egress: LiveKit’s Egress system offers server-side recording of room audio and video. While recordings are saved to cloud storage initially, you can easily download them to your local device once the process is done.
If you let me know which SDK or method you're using, I’d be more than happy to walk you through the next steps with some tailored guidance!
Sources: Processing raw media tracks | LiveKit Docs | examples/save_to_disk/src/main.rs | Tests/LiveKitTests/AudioEngineTests.swift | sample-app-record-local/README.md | examples/receive-audio/index.tsable-jackal-84140
10/03/2025, 7:15 AMtall-airline-16756
10/03/2025, 7:16 AMRecorderIO class from the livekit.agents.voice.recorder_io module to record audio during an agent session and save it locally in OGG/Opus format. This way, you’ll capture both the input (user audio) and output (agent responses) streams within the session, making it easy to keep track of everything.
If you’re interested in recording the entire room’s audio, LiveKit’s Egress feature is a great option. Just a heads-up, Egress recordings are meant to be saved to cloud storage like S3, GCP, or Azure. While it doesn’t support saving directly to your local device, you can always download the recordings from the cloud once the process is done.
Feel free to reach out if you’d like more details or examples on how to use RecorderIO or set up Egress—I’m here to help!
Sources: livekit-api/livekit/api/egress_service.py | Processing raw media tracks | LiveKit Docs | Session recording and transcripts | LiveKit Docs | docs/index.yaml | livekit-agents/livekit/agents/voice/recorder_io/recorder_io.pyable-jackal-84140
10/03/2025, 8:17 AMtall-airline-16756
10/03/2025, 8:18 AMrtc.AudioStream(track) to receive audio frames asynchronously, which is super handy.
3. Write to a WAV file: Convert the frame data to int16 format and write it to a file with a properly formatted WAV header.
Here’s a Python example to get you started:
import asyncio
import wave
from livekit import rtc
async def save_audio_to_wav(audio_stream: rtc.AudioStream, file_path: str):
with wave.open(file_path, 'wb') as wav_file:
# Assume 48kHz, 1 channel, 16-bit samples
sample_rate = 48000
num_channels = 1
sample_width = 2 # bytes per sample (16-bit)
wav_file.setframerate(sample_rate)
wav_file.setnchannels(num_channels)
wav_file.setsampwidth(sample_width)
async for frame in audio_stream:
# Write raw PCM data to WAV
wav_file.writeframes(frame.data)
# In your event handler:
@room.on("track_subscribed")
def on_track_subscribed(track: rtc.Track, publication, participant):
if track.kind == rtc.TrackKind.KIND_AUDIO:
audio_stream = rtc.AudioStream(track)
asyncio.ensure_future(save_audio_to_wav(audio_stream, "output.wav"))
This script sets up a WAV file and writes the raw PCM data from each audio frame it receives directly into it. If you have any questions or want me to help you with a complete working script, just let me know—I’m here to help!
Sources: Processing raw media tracks | LiveKit Docs | examples/save_to_disk/src/main.rs | Session recording and transcripts | LiveKit Docs | Track egress | LiveKit Docsable-jackal-84140
10/03/2025, 8:28 AMtall-airline-16756
10/03/2025, 8:29 AMrtc.AudioStream to grab raw audio frames and then write them straight to a WAV file with Python's handy built-in wave module. This method keeps things straightforward and is perfect if you're working with short audio clips.
Here’s a clear example to get you started:
import wave
from livekit import rtc
async def save_audio_simple(audio_stream: rtc.AudioStream, file_path: str):
with wave.open(file_path, 'wb') as wav_file:
wav_file.setframerate(48000) # 48kHz sample rate
wav_file.setnchannels(1) # Mono audio
wav_file.setsampwidth(2) # 16-bit samples
async for frame in audio_stream:
wav_file.writeframes(frame.data)
@room.on("track_subscribed")
def on_track_subscribed(track: rtc.Track, publication, participant):
if track.kind == rtc.TrackKind.KIND_AUDIO:
audio_stream = rtc.AudioStream(track)
asyncio.ensure_future(save_audio_simple(audio_stream, "output.wav"))
This approach writes audio frames directly to a WAV file without any extra processing. If you have any questions or want help customizing this further, just let me know—I’m here to help!
Sources: Capturing the First Few Seconds of a Call for Processing | Session recording and transcripts | LiveKit Docs | examples/save_to_disk/src/main.rs | examples/filesaver/main.go | list_devices.py