Recording Calls

Call recording is an essential feature for many applications using Stream’s Video SDK. It enables you to capture and store call audio for compliance requirements, training purposes, and detailed analysis of past conversations.

Stream offers two approaches to audio recording: single track and composite. Single track recording saves each participant’s audio separately, giving you more flexibility for post-processing and the ability to work with individual speakers’ content. Composite recording, on the other hand, combines everyone into one audio file - similar to what participants hear during the call. This makes it simpler to share and play back, though with less flexibility for manipulation afterwards.

The choice between these methods depends on your needs. Single track is great when you need to process speakers individually, while composite works better for straightforward playback and sharing. Additionally, Stream supports diarization, which helps identify and separate different speakers in your recordings, making it easier to analyze who said what during the call.

Basics

To record call audio, we first need to connect a recorder bot to the call.

from uuid import uuid4
from getstream.models import UserRequest
from getstream.stream import Stream

# Load environment variables
load_dotenv()

# Initialize Stream client
client = Stream.from_env()

# ...add your call creation and other initialisations here

# Create recorder bot
recorder_user_id = f"bot-recorder-{str(uuid4())[:8]}"
client.upsert_users(UserRequest(id=recorder_user_id, name="Recorder Bot"))

Before we start recording, the recorder bot must join the call first:

async with await rtc.join(call, recorder_user_id) as recorder_connection:

    # Implement call recording - look at the next sections

Single-track recording

To record single track audio, you can provide the RecordingType.TRACK recording type. The user_id_filter parameter specifies which user’s track to record. The output_dir parameter specifies the location of the resultant recording.

recording_params = {
    "recording_types": [RecordingType.TRACK],
    "output_dir": "recordings/tracks",
    "user_id_filter": "user_id_to_record",
}

recorder_connection.start_recording(**recording_params)

Composite recording

To record composite audio from all the participants, you can provide the RecordingType.COMPOSITE recording type. The output directory specifies the location of the resultant recording.

recording_params = {
    "recording_types": [RecordingType.COMPOSITE],
    "output_dir": "recordings/composite",
}

recorder_connection.start_recording(**recording_params)

Stop recording

To stop recording, you can simply call the connection.stop_recording() method:

connection.stop_recording()

Full Example

You can find a complete working example of call recording in our GitHub repository.

This example demonstrates both single-track and composite recording in a practical implementation.

© Getstream.io, Inc. All Rights Reserved.