Can we record audio and video chat with the agent ...
# ask-ai
l
Can we record audio and video chat with the agent locally? For swift and flutter, can you show me example codes and doc?
t
Thanks for reaching out, James. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
You can record audio and video chat locally with LiveKit, but the approach and available features differ between the Swift and Flutter SDKs. Swift SDK – Local Audio Recording • LocalAudioTrackRecorder: Record audio from a local track in various formats and sample rates. • AudioMixRecorder: Record audio from multiple sources (e.g., local and remote tracks) to a file in real time. • AudioManager: Supports pre-connection recording and advanced audio engine features.
Copy code
// Example: Record local audio track
let localTrack = LocalAudioTrack.createTrack(options: .noProcessing)
let recorder = LocalAudioTrackRecorder(track: localTrack, format: .pcmFormatInt16, sampleRate: 48000)
let stream = try await recorder.start()
for await data in stream {
    // Process or save audio data
}
recorder.stop()
Copy code
// Example: Record multiple audio sources to file
let recordFilePath = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent("recording.aac")
let recorder = try AudioMixRecorder(filePath: recordFilePath, audioSettings: [AVFormatIDKey: kAudioFormatMPEG4AAC, AVSampleRateKey: 16000, AVNumberOfChannelsKey: 1])
try recorder.start()
let remoteSource = recorder.addSource()
let localSource = recorder.addSource()
remoteAudioTrack.add(audioRenderer: remoteSource)
localAudioTrack.add(audioRenderer: localSource)
recorder.stop()
Flutter SDK – Local Track Creation and Publishing • You can create and publish local audio and video tracks, including camera and screen share. • Direct local file recording is not built-in; you may need to implement this using platform-specific code or third-party packages.
Copy code
// Example: Create and publish local video track
var localVideo = await LocalVideoTrack.createCameraTrack();
await room.localParticipant.publishVideoTrack(localVideo);

// Example: Create and publish local audio track
var localAudio = await LocalAudioTrack.createTrack();
await room.localParticipant.publishAudioTrack(localAudio);
For advanced processing, the Flutter SDK supports track processors for custom audio/video manipulation before publishing. Android Reference: The Android SDK provides a sample app (
sample-app-record-local
) that demonstrates saving local audio and video tracks to a file using native APIs. Documentation and Code References: • Swift SDK:
LocalAudioTrackRecorder
,
AudioMixRecorder
,
AudioManager
• Flutter SDK:
LocalVideoTrack.createCameraTrack()
,
LocalAudioTrack.createTrack()
• Android:
VideoFileRenderer
sample for local recording For iOS, ensure you have the correct permissions in your
Info.plist
for camera and microphone access, and background audio if needed. If you need more detailed examples for a specific use case (e.g., saving video to file in Flutter), let me know your target platform and requirements. Sources: Sources/LiveKit/Support/AudioMixRecorder.swift | README.md | sample-app-record-local/src/main/java/io/livekit/android/sample/record/Vide... | Camera & microphone | LiveKit Docs