Daily
WebRTC transport implementation using Daily for real-time audio/video communication
Overview
DailyTransport
provides real-time audio and video communication capabilities using Daily’s WebRTC platform. It supports bidirectional audio/video streams, transcription, voice activity detection (VAD), and participant management.
Installation
To use DailyTransport, install the required dependencies:
You’ll also need to set up your Daily API key as an environment variable:
DAILY_API_KEY
.
You can obtain a Daily API key by signing up at Daily.
Configuration
Constructor Parameters
Daily room URL
Daily room token
Name of the bot in the room
Transport configuration parameters
DailyParams Configuration
Daily API endpoint URL
Daily API key for authentication
Audio Output Configuration
Enable audio output capabilities
Enable live audio streaming mode
Audio output sample rate in Hz
Number of audio output channels
Audio output bitrate in bits per second
Audio Input Configuration
Enable audio input capabilities
Audio input sample rate in Hz
Number of audio input channels
Audio filter for input processing. Supported filters are: KrispFilter()
and
NoisereduceFilter()
. See the KrispFilter()
reference
docs and NoisereduceFilter()
reference docs` for more
information.
Video Output Configuration
Enable video output capabilities
Enable live video streaming mode
Video output width in pixels
Video output height in pixels
Video output bitrate in bits per second
Video output frame rate
Video color format (RGB, BGR, etc.)
Voice Activity Detection (VAD)
Enable voice activity detection
Pass through audio during VAD
Voice Activity Detection analyzer. You can set this to either
SileroVADAnalyzer()
or WebRTCVADAnalyzer()
. SileroVADAnalyzer is the
recommended option. Learn more about the
SileroVADAnalyzer.
Feature Settings
Configuration for dial-in functionality
Enable real-time transcription
Configuration for transcription features
Basic Usage
Event Callbacks
DailyTransport provides a comprehensive callback system for handling various events. Register callbacks using the @transport.event_handler()
decorator.
Connection Events
Called when the bot successfully joins the room.
Parameters:
transport
: The DailyTransport instancedata
: Dictionary containing room join information
Called when the bot leaves the room.
Parameters:
transport
: The DailyTransport instance
Participant Events
Called when the first participant joins the room. Useful for initializing conversations.
Parameters:
transport
: The DailyTransport instanceparticipant
: Dictionary containing participant information
Called when any participant joins the room.
Parameters:
transport
: The DailyTransport instanceparticipant
: Dictionary containing participant information
Called when a participant leaves the room.
Parameters:
transport
: The DailyTransport instanceparticipant
: Dictionary containing participant informationreason
: String describing why the participant left,“leftCall” | “hidden”
Event emitted when a participant is updated. This can mean either the participant’s metadata was updated, or the tracks belonging to the participant changed.
Parameters:
transport
: The DailyTransport instanceparticipant
: Dictionary containing updated participant information
Communication Events
Event emitted when a custom app message is received from another participant or via the REST API.
Parameters:
transport
: The DailyTransport instancemessage
: The message content (any type)sender
: String identifier of the message sender
Event emitted when the call state changes, normally as a consequence of joining or leaving the call.
Parameters:
transport
: The DailyTransport instancestate
: String representing the new call state. Learn more about call states.
Dial Events
Dial-in
Event emitted when dial-in is ready. This happens after the room has connected to the SIP endpoint and the system is ready to receive dial-in calls.
Parameters:
transport
: The DailyTransport instancesip_endpoint
: String containing the SIP endpoint information
Event emitted when the session with the dial-in remote end is established (i.e. SIP endpoint or PSTN are connectd to the Daily room).
Note: connected does not mean media (audio or video) has started flowing between the room and PSTN, it means the room received the connection request and both endpoints are negotiating the media flow.
Parameters:
transport
: The DailyTransport instancedata
: Dictionary containing connection information. See DialinConnectedEvent.
Event emitted when the dial-in remote end disconnects the call.
Parameters:
transport
: The DailyTransport instancedata
: Dictionary containing connection information. See DialinStoppedEvent.
Event emitted in the case of dial-in errors which are fatal and the service cannot proceed. For example, an error in SDP negotiation is fatal to the media/SIP pipeline and will result in dialin-error being triggered.
Parameters:
transport
: The DailyTransport instancedata
: Dictionary containing error information. See DialinEvent.
Event emitted there is a dial-in non-fatal error, such as the selected codec not being used and a fallback codec being utilized.
Parameters:
transport
: The DailyTransport instancedata
: Dictionary containing warning information. See DialinEvent.
Dial-out
Event emitted when the session with the dial-out remote end is answered.
Parameters:
transport
: The DailyTransport instancedata
: Dictionary containing call information. Learn more.
Event emitted when the session with the dial-out remote end is established.
Parameters:
transport
: The DailyTransport instancedata
: Dictionary containing connection information. Learn more.
Event emitted when the dial-out session is stopped.
Parameters:
transport
: The DailyTransport instancedata
: Dictionary containing connection information. Learn more.
Event emitted in the case of dial-out errors which are fatal and the service cannot proceed. For example, an error in SDP negotiation is fatal to the media/SIP pipeline and will result in dialout-error being triggered.
Parameters:
transport
: The DailyTransport instancedata
: Dictionary containing error information.Learn more.
Event emitted there is a dial-out non-fatal error, such as the selected codec not being used and a fallback codec being utilized.
Parameters:
transport
: The DailyTransport instancedata
: Dictionary containing warning information. Learn more.
Transcription Events
Called when a transcription message is received. This includes both interim and final transcriptions.
Parameters:
transport
: The DailyTransport instancemessage
: Dictionary containing transcription data including. Learn more.
Recording Events
Called when a room recording starts successfully.
Parameters:
transport
: The DailyTransport instancestatus
: Dictionary containing recording status information. Learn more.
Called when a room recording stops.
Parameters:
transport
: The DailyTransport instancestream_id
: String identifier of the stopped recording stream
Called when an error occurs during recording.
Parameters:
transport
: The DailyTransport instancestream_id
: String identifier of the recording streammessage
: Error message describing what went wrong
Error Events
Called when a transport error occurs.
Parameters:
transport
: The DailyTransport instanceerror
: String containing error details
Notes on Callbacks
- All callbacks are asynchronous
- Callbacks are executed in the order they were registered
- Multiple handlers can be registered for the same event
- Exceptions in callbacks are logged but don’t stop the transport
- Callbacks should be lightweight to avoid blocking the event loop
- Heavy processing should be offloaded to separate tasks
Frame Types
Input Frames
Raw audio data from participants
Video frames from participants
Output Frames
Audio data to be sent
Video frames to be sent
Methods
Room Management
Media Control
Sends an image frame to the room.
Parameters:
frame
: Image frame to send, either raw image data or sprite animation
Sends an audio frame to the room.
Parameters:
frame
: Audio frame to send
Video Management
Starts capturing video from a specific participant.
Parameters:
participant_id
: ID of the participant to captureframerate
: Target frame rate (default: 30)video_source
: Video source type (default: “camera”)color_format
: Color format of the video (default: “RGB”)
Transcription Control
Starts capturing and transcribing audio from a specific participant.
Parameters:
participant_id
: ID of the participant to transcribe
Updates the transcription configuration for specific participants or instances.
Parameters:
participants
: Optional list of participant IDs to transcribe. If None, transcribes all participants.instance_id
: Optional specific transcription instance ID to update
Example:
Recording Control
Starts recording the room session.
Parameters:
streaming_settings
: Recording configuration settingsstream_id
: Optional stream identifierforce_new
: Force start a new recording
See start_recording for more details.
Stops an active recording.
Parameters:
stream_id
: Optional stream identifier to stop specific recording
See stop_recording for more details.
Dial-out Control
Initiates a dial-out call.
Parameters:
settings
: Dial-out configuration settings
See start_dialout for more details.
Stops an active dial-out call.
Parameters:
participant_id
: ID of the participant to disconnect
See stop_dialout for more details.
Subscription Management
Updates subscriptions and subscription profiles. This function allows you to update subscription profiles and at the same time assign specific subscription profiles to a participant and even change specific settings for some participants.
Parameters:
participant_settings
: Per-participant subscription settingsprofile_settings
: Global subscription profile settings
See update_subscriptions for more details.
Properties
Returns the transport’s participant ID in the room.
Notes
- Supports real-time audio/video communication
- Handles WebRTC connection management
- Provides voice activity detection
- Includes transcription capabilities
- Manages participant interactions
- Supports recording and streaming
- Thread-safe processing
- All callbacks are asynchronous
- Multiple handlers can be registered for the same event
- Exceptions in callbacks are logged but don’t stop the transport