astonishing-salesclerk-9701
12/13/2025, 3:34 PMtall-airline-16756
12/13/2025, 3:34 PMtall-airline-16756
12/13/2025, 3:34 PMSILENCE_THRESHOLD = 300 # seconds
last_active = time.time()
def on_participant_activity():
nonlocal last_active
last_active = time.time()
async def monitor():
while True:
if time.time() - last_active > SILENCE_THRESHOLD:
await room.remove_participant(participant_sid) # disconnect single participant
break
await asyncio.sleep(1)
• End the whole session (all participants) using the room-delete API:
◦ Call the DeleteRoom / room end endpoint to terminate the room and close all connections immediately.
Which would you prefer — disconnect a single participant after inactivity, or end the whole room? If you want, tell me which SDK/server language you're using and I’ll provide a concrete code example for that environment.
Sources: examples/voice_agents | livekit/livekit_composite | DeepWiki | How to detect and handle silence during calls | Job lifecycle | LiveKit docsastonishing-salesclerk-9701
12/13/2025, 3:35 PMtall-airline-16756
12/13/2025, 3:36 PMastonishing-salesclerk-9701
12/13/2025, 3:36 PMtall-airline-16756
12/13/2025, 3:36 PMimport requests
import time
from typing import Optional
LIVEKIT_URL = "https://your-livekit-host" # e.g. https://livekit.example.com
API_KEY = "your_api_key"
API_SECRET = "your_api_secret"
def delete_room(room_name: str) -> bool:
url = f"{LIVEKIT_URL}/rooms/{room_name}"
# Basic auth using API key/secret
resp = requests.delete(url, auth=(API_KEY, API_SECRET))
return resp.status_code == 204 or resp.status_code == 200
# Example: called when speech detected
def on_speech_detected(room_name: str):
deleted = delete_room(room_name)
if deleted:
print(f"Room {room_name} deleted")
else:
print(f"Failed to delete room {room_name}: check logs/status")
# --- Example usage: simulate speech detection ---
if __name__ == "__main__":
ROOM = "my-room"
# Simulate server receiving a speech event (replace with real detection)
time.sleep(1)
on_speech_detected(ROOM)
Notes and suggestions
• Ensure your API key/secret have permission to manage rooms.
• If you prefer the official server SDK for Python (if available in your environment), use its DeleteRoom helper; otherwise the REST DELETE above works.
• If you only want to end the room when a specific participant speaks, include the participant ID in your speech event and verify before calling delete_room.
• To avoid race conditions, consider checking room state before delete or add a short debounce if many speech events arrive almost simultaneously.
Would you like a concrete example that shows:
• a) detecting speech from client-side (browser) and sending a server event, or
• b) server-side audio-level detection code (if you already ingest audio)?
Tell me which and I’ll provide the code.astonishing-salesclerk-9701
12/13/2025, 3:37 PMtall-airline-16756
12/13/2025, 3:37 PMimport requests
LIVEKIT_URL = "https://your-livekit-host" # e.g. https://livekit.example.com
API_KEY = "your_api_key"
API_SECRET = "your_api_secret"
def delete_room(room_name: str) -> bool:
url = f"{LIVEKIT_URL}/rooms/{room_name}"
resp = requests.delete(url, auth=(API_KEY, API_SECRET))
return resp.status_code in (200, 204)
def on_server_detected_speech(room_name: str, participant_id: str = None):
# Optionally verify participant_id if you only end room for specific participants
success = delete_room(room_name)
if success:
print(f"Deleted room {room_name}")
else:
print(f"Failed to delete room {room_name}: {resp.status_code if 'resp' in locals() else 'error'}")
If you want, tell me which server-side method you’ll use to detect speech (RTP ingest + VAD, transcription/webhook, or forwarded client VAD events) and I’ll provide a tailored code snippet for that method.