from getstream.video import rtc
# Connect to a call
async with await rtc.join(call, user_id) as connection:
# Listen for participant events
@connection.on("participant_joined")
async def on_participant_joined(participant):
print(f"Participant {participant.user_id} joined")
# Listen for audio data
@connection.on("audio")
async def on_audio(pcm_data, user):
print(f"Received audio from {user}")
# Listen for connection state changes
@connection.on("connection.state_changed")
async def on_connection_state_changed(event):
print(f"Connection state: {event['old']} -> {event['new']}")
# Wait for the connection to end
await connection.wait()
Events Reference
This is a list of events emitted by the SDK and the various plugin types.
This event system provides a unified, event-driven architecture that allows plugins to be composed and integrated into audio processing pipelines.
Events Emitted by Plugins
All plugins inherit from base classes (STT, TTS, VAD, STS) that define standard event patterns using AsyncIOEventEmitter
. Events include rich metadata for debugging and monitoring.
Note: all audio events use PCM format.
Plugin Category | Event Name | Description | Notes |
---|---|---|---|
All Plugins | error | Emitted when an error occurs during processing | Includes connection errors, API errors, processing failures, and synthesis errors. Provides consistent error handling across the ecosystem |
STT (Speech-to-Text) | transcript | Emitted when a complete transcript is available | Final transcription result with confidence scores and processing metadata |
partial_transcript | Emitted when a partial transcript is available during real-time processing | Only emitted by streaming STT services like Deepgram; not by batch processors like Moonshine | |
TTS (Text-to-Speech) | audio | Emitted when an audio chunk is generated | Contains raw PCM audio data ready for playback |
VAD (Voice Activity Detection) | audio | Emitted when speech is detected and accumulated | Contains complete speech segments after silence detection |
partial | Emitted periodically while speech is ongoing | Emitted every N frames during active speech detection (configurable) | |
STS (Speech-to-Speech) | connected | Emitted when the WebSocket connection is established | Indicates successful handshake with OpenAI Realtime API |
disconnected | Emitted when the connection is closed | Indicates normal closure or error disconnection | |
All OpenAI events | All events from OpenAI Realtime API are forwarded verbatim | Includes conversation events, function calls, responses, errors, etc. |
Events Emitted by the Python AI SDK
Notes
- Event Architecture: The RTC module uses a hierarchical event system where:
- Low-level components emit specific events
- Higher-level managers aggregate and forward events
- SFU events are automatically forwarded from the signaling layer
- SFU Events: All SFU (Selective Forwarding Unit) events are automatically forwarded through the signaling layer, providing real-time updates about call state, participants, media streams, and connection quality. SFU events can be listened to from the SDK as they are forwarded by the
ConnectionManager
class.
A full list of SFU events Stream emits is also available.
Recording Events: Comprehensive recording event system supports both per-user and composite recording with detailed lifecycle tracking.
Network Monitoring: Built-in network monitoring provides connectivity state changes for robust connection handling.
WebRTC Integration: Events closely follow WebRTC standards for peer connection management, ICE handling, and media track lifecycle.
Component | Event Name | Description | Notes |
---|---|---|---|
Connection Manager | connection.state_changed | Emitted when connection state changes | Contains old and new state values |
Events emitted by the SDK are forwarded | Includes SFU events, so most events can be listened for from the connection manager | ||
Network Monitor | network_changed | Emitted when network connectivity status changes | Contains online (boolean) and timestamp |
network_online | Emitted when network comes online | Contains timestamp | |
network_offline | Emitted when network goes offline | Contains timestamp | |
Participants | participant_joined | Emitted when a participant joins the call | Contains participant data from SFU |
participant_left | Emitted when a participant leaves the call | Contains participant data from SFU | |
Peer Connection | audio | Emitted when audio PCM data is received from a track | Contains PCM data and user metadata |
track_added | Emitted when a new media track is added | Contains track and user metadata | |
Reconnection Manager | reconnection_failed | Emitted when reconnection attempts fail | Contains reason for failure (timeout, error, etc.) |
reconnection_success | Emitted when reconnection succeeds | Contains strategy used and duration of reconnection process | |
Recording Manager | recording_started | Emitted when recording begins | Contains recording types, user IDs, output directory |
recording_stopped | Emitted when recording ends | Contains recording types, user IDs, duration | |
user_recording_started | Emitted when recording starts for a specific user | Contains user ID, track type, filename | |
user_recording_stopped | Emitted when recording stops for a specific user | Contains user ID, track type, filename, duration | |
composite_recording_started | Emitted when composite recording begins | Contains track type, filename | |
composite_recording_stopped | Emitted when composite recording ends | Contains track type, filename, duration | |
recording_error | Emitted when recording encounters an error | Contains error type, user ID, track type, message | |
SFU Events (via Signaling) | subscriber_offer | SDP offer for establishing subscriber PeerConnection | WebRTC signaling |
publisher_answer | SDP answer for publisher PeerConnection | WebRTC signaling | |
connection_quality_changed | Connection quality updates for participants | Network quality metrics | |
audio_level_changed | Audio level changes for participants | Voice activity indicators | |
ice_trickle | ICE candidate for connection establishment | WebRTC connectivity | |
change_publish_quality | Quality adjustment recommendations | Bandwidth optimization | |
dominant_speaker_changed | Current dominant speaker notification | For spotlight/focus views | |
join_response | Acknowledgment of successful call join | Initial connection response | |
health_check_response | Response to health check with participant count | Connection monitoring | |
track_published | New track published by participant | Media stream notifications | |
track_unpublished | Track no longer published | Media stream notifications | |
error | SFU error communication | Connection/processing errors | |
call_grants_updated | Track publishing permissions changed | Permission management | |
go_away | Migration instruction from SFU | Load balancing/failover | |
ice_restart | ICE restart instruction | Connection recovery | |
pins_updated | Pinned participants list changed | UI state management | |
call_ended | Call termination notification | Session lifecycle | |
participant_updated | Participant data updated | User state changes | |
participant_migration_complete | Migration process completed | Failover completion | |
change_publish_options | Publishing configuration changes | Codec/quality updates | |
inbound_state_notification | Inbound video state changes | Stream status updates | |
Coordinator WebSocket | Various API events | All Stream API events forwarded | Real-time API notifications |