narrow-laptop-64001
03/10/2026, 7:33 PMtall-airline-16756
03/10/2026, 7:33 PMtall-airline-16756
03/10/2026, 7:34 PMSILENCE_THRESHOLD = 5 # seconds
async def monitor_interaction():
while connected:
if time.time() - remote_last_spoke_time > SILENCE_THRESHOLD:
# either trigger voicemail flow or hang up
await trigger_voicemail_flow() # or await hangup_call()
await asyncio.sleep(1)
When to use: Low-latency, low-complexity deployments where you can tolerate occasional false positives (e.g., a quiet human).
2) LLM / transcript-based voicemail detection (better accuracy)
• Record or stream the initial few seconds of the remote audio to a speech-to-text service.
• Run a short intent/classification check for typical voicemail phrases (“leave a message,” “I’m not available,” long greeting patterns).
• If the classifier signals voicemail, call a handler that either leaves a pre-recorded message, instructs the agent to leave a message, or closes the call.
Example flow:
• Start speech-to-text immediately after answer.
• If transcript matches voicemail patterns, call a function like detected_answering_machine() that generates/plays a short message and then ends the call.
When to use: When you need higher accuracy and can accept additional latency and processing.
3) Twilio SIP trunk configuration (reduce signaling issues)
• Ensure your Twilio SIP trunk is configured to support proper transfer behavior (SIP REFER) and caller ID passthrough so calls appear legitimate and are less likely to be handled by auto-systems.
• Proper SIP signaling helps avoid improper answers and supports server-side transfers if you need to route calls to voicemail systems.
When to use: Always — it prevents signaling-related failures and improves compatibility with carrier and voicemail infrastructure.
4) Hang up / clean room teardown in LiveKit
• When you decide to end the call (either after leaving a message or upon detecting voicemail), terminate the LiveKit session so the agent doesn’t remain connected to dead air.
• Use the API to delete the room or end the participant’s connection; for example, call your room deletion or disconnect function to close the session programmatically.
When to use: Every voicemail-handling flow — prevents wasted agent time and ensures predictable billing/usage.
Practical tips and trade-offs
• Threshold tuning: Start with ~4–6 seconds for silence detection and adjust by monitoring false positives/negatives in real calls.
• Combination: Use silence detection as a cheap first filter, then run transcript analysis on those candidates to confirm voicemail before taking action.
• Recording consent: Be sure you follow legal/regulatory rules for recording or playing automated messages in the regions you call.
• UX: If an agent is live, consider a brief warning before handing off to voicemail automation so the agent can override if needed.
If you’d like, I can help next with:
• Specific code snippets for your stack (Node/Python) to monitor remote voice activity in LiveKit.
• Example prompt and logic for an LLM classifier that detects voicemail phrases.
• Recommended Twilio trunk settings or exact API calls you should run for caller ID passthrough and transfer behavior.
Which of those would you prefer me to provide next?
Sources: How to detect and handle silence during calls | Agents telephony integration | LiveKit Documentation | Preserve caller ID during SIP transfers with Twilio | LiveKit