Twilio Integration
This guide walks you through integrating Kallglot with Twilio for real-time voice translation on phone calls.Prerequisites
- A Twilio account with a phone number
- A Kallglot API key
- A web server to receive webhooks
Architecture
Setup Steps
1. Configure Your Twilio Number
In the Twilio Console:- Go to Phone Numbers > Manage > Active Numbers
- Select your number
- Under Voice & Fax, set:
- A Call Comes In: Webhook
- URL:
https://your-app.com/webhooks/twilio/voice - Method: POST
2. Create the Webhook Handler
Kallglot does not currently provide official SDKs. The helper functions in these examples, such as
createKallglotSession(...), represent ordinary HTTPS calls to the API.3. Handle Session Events
Set up a webhook to receive session events:Advanced Configurations
Outbound Calls
For outbound calls, create the session first, then initiate the call:Conference Calls
For multi-party calls, use Twilio Conferences:Dynamic Language Detection
Let Kallglot auto-detect the customer’s language:Error Handling
Handle Session Creation Failures
Handle Stream Disconnections
Twilio sends a status callback when the stream disconnects:Best Practices
Use track: 'both_tracks'
Use track: 'both_tracks'
Always use
track: 'both_tracks' to send both inbound and outbound audio to Kallglot. This ensures proper speaker separation.Handle race conditions
Handle race conditions
The Twilio webhook must respond quickly (within 15 seconds). Create the session and respond immediately:
Clean up on call end
Clean up on call end
End Kallglot sessions when calls complete to stop billing:
Troubleshooting
No audio in translation
- Verify the stream URL is correct
- Check that
track: 'both_tracks'is set - Verify the WebSocket connection is established
High latency
- Ensure your server is geographically close to Twilio’s region
- Check network latency between your server and Kallglot
- Consider using Twilio’s edge locations
Echo or feedback
- Ensure you’re not playing translated audio back to the source
- Check that speaker identification is working correctly