little-king-41579
02/17/2026, 9:08 AMtall-airline-16756
02/17/2026, 9:09 AMtall-airline-16756
02/17/2026, 9:09 AMfrom livekit import rtc
async def ensure_audio_subscription(room: rtc.Room):
"""
Ensure all remote participants' audio tracks are subscribed.
Typically not necessary when auto-subscribe is enabled, but useful
if auto-subscribe is disabled or you want to re-subscribe.
"""
for participant in room.remote_participants.values():
for pub in participant.track_publications.values():
# Only handle published audio tracks
if pub.track and pub.track.kind == rtc.TrackKind.KIND_AUDIO:
# If currently not subscribed, request subscription
if not pub.is_subscribed:
try:
await pub.set_subscribed(True)
print(f"Subscribed to audio track {pub.sid} from {participant.identity}")
except Exception as e:
print(f"Failed to subscribe to {pub.sid} from {participant.identity}: {e}")
Usage example (hook on participant connected):
@server.room.on("participant_connected")
async def on_participant_connected(participant: rtc.RemoteParticipant):
# room is available via server.room in this example
await ensure_audio_subscription(server.room)
If you want to start the client with explicit auto-subscribe settings when connecting:
# When constructing/connecting the client, enable audio auto-subscribe
room = await rtc.connect(url, token, auto_subscribe=rtc.AutoSubscribe.AUDIO_AND_VIDEO)
If this doesn’t solve your case, a few quick clarifying questions to help further:
• Are you using auto-subscribe (default) or do you need manual subscription control?
• Are you working with the server-side SDK (Agents/framework) or client SDKs running in browsers/native apps?
• Any errors or specific behavior you’re seeing when participants join (no audio, one-way audio, track published but not heard)?
I can provide adjusted code samples for:
• Manual subscribe/unsubscribe flows,
• Handling per-participant mute/unmute,
• Client-side (browser/native) subscription examples if needed.
Which of the above would you like next?
Sources: Client SDKs | livekit/livekit_composite | DeepWiki | Capturing the First Few Seconds of a Call for Processing | livekit/livekit_composite | DeepWiki