creamy-byte-34126
06/25/2025, 9:53 PMtall-airline-16756
06/25/2025, 9:53 PMtall-airline-16756
06/25/2025, 9:54 PMimport asyncio
import time
SILENCE_THRESHOLD = 5 # seconds
async def entrypoint(ctx: JobContext):
user_last_spoke_time = time.time()
monitor_task = None
async def monitor_interaction():
while True:
if time.time() - user_last_spoke_time > SILENCE_THRESHOLD:
<http://logger.info|logger.info>("silent for too long! disconnecting")
try:
await ctx.room.disconnect()
except Exception as e:
logger.exception("Error while ending call")
else:
logger.trace("silence is not enough to disconnect")
await asyncio.sleep(1)
@agent.on("user_started_speaking")
def on_user_started_speaking(_msg: llm.ChatMessage):
user_last_spoke_time = time.time()
monitor_task = asyncio.create_task(monitor_interaction())
agent.start(ctx.room, participant)
async def on_shutdown():
<http://logger.info|logger.info>("shutting down session")
if monitor_task:
monitor_task.cancel()
ctx.add_shutdown_callback(on_shutdown)
This example monitors silence during a call and disconnects if the silence exceeds a specified threshold (e.g., 5 seconds). You can modify the logic to include prompts like "Are you there?" before disconnecting.
Unfortunately, I couldn't find a specific example for implementing a call time limit feature. If you need further assistance with that, please let me know!
Sources: How to detect and handle silence during callsfew-dog-48918
06/28/2025, 12:41 AMcreamy-byte-34126
06/28/2025, 2:43 AMfew-dog-48918
06/28/2025, 2:45 AM