- LiveKit Telephony Integration
- How it works
- Before you begin
- Step 1: Configure Telnyx SIP connection
- Step 2: Configure LiveKit SIP trunks
- Inbound trunk
- Dispatch rule
- Outbound trunk (optional)
- Step 3: Build your LiveKit agent with AssemblyAI
- Prerequisites
- Agent code
- Environment variables
- Run the agent
- Testing outbound calls
- Troubleshooting
- Pipecat Integration
- Prerequisites
- How it works
- Dial-in Setup
- Step 1: Create TeXML application
- Step 2: Configure Telnyx phone number
- Step 3: Build your bot
- Dial-out Setup
- How dial-out works
- Bot configuration for dial-out
- Key Features
- Advanced Configuration
- Resources
Integrate Telnyx with AssemblyAI
Telnyx is a global connectivity platform that provides programmable voice, messaging, and wireless services. By combining Telnyx with AssemblyAI, you can build real-time voice agents with industry-leading speech recognition accuracy and advanced turn detection.
This guide shows you how to integrate Telnyx with AssemblyAI using two popular voice agent orchestrators: LiveKit and Pipecat.
LiveKit Telephony Integration
LiveKit is a real-time communication platform for building voice, video, and data applications. You can integrate Telnyx SIP trunking with LiveKit to enable phone calls to your voice agents that use AssemblyAI for speech recognition.
How it works
Telnyx SIP trunks bridge phone calls into LiveKit rooms as special SIP participants. Your LiveKit agent (configured with AssemblyAI STT) connects to the room and interacts with the caller. The flow is:
- Phone call → Telnyx SIP trunk
- Telnyx → LiveKit room (creates SIP participant)
- LiveKit agent (with AssemblyAI STT) → joins room and handles conversation
Before you begin
- Telnyx account: Create an account and purchase a phone number at telnyx.com
- LiveKit project: Get your SIP URI from your LiveKit project settings
- LiveKit CLI: Install the LiveKit CLI on your computer
- Environment variables: Configure
LIVEKIT_URL,LIVEKIT_API_KEY,LIVEKIT_API_SECRET, andASSEMBLYAI_API_KEY
Step 1: Configure Telnyx SIP connection
Configure your Telnyx SIP connection to route calls to LiveKit. Follow the detailed setup guide:
Telnyx LiveKit SIP Configuration Guide
Key steps:
- Create a SIP connection in Telnyx Mission Control Portal
- Set connection type to FQDN and provide your LiveKit SIP URI
- Configure outbound call authentication (username/password)
- Assign your phone number(s) to the SIP connection
Step 2: Configure LiveKit SIP trunks
Create inbound and outbound SIP trunks in LiveKit using the LiveKit CLI.
Inbound trunk
Create inboundTrunk.json:
Create the trunk:
Save the returned SIPTrunkID for the next step.
Dispatch rule
Create dispatchRule.json to route incoming calls to your agent:
Create the dispatch rule:
This automatically dispatches your agent to each incoming call in a new room.
Outbound trunk (optional)
For outbound calling, create outboundTrunk.json:
Create the trunk:
Step 3: Build your LiveKit agent with AssemblyAI
Create a LiveKit agent that uses AssemblyAI for speech recognition. Once your SIP trunks and dispatch rules are configured, no special telephony code is required—the agent simply joins the room when a call comes in.
Prerequisites
Setup and activate a virtual environment:
Install the required dependencies:
Download model files:
Agent code
Here’s a minimal agent using AssemblyAI STT:
Environment variables
Set the following environment variables:
Run the agent
Start your agent:
Now dial your Telnyx phone number to test the integration. The call will be routed through Telnyx → LiveKit → your agent with AssemblyAI speech recognition.
Testing outbound calls
To test an outbound call, create sipParticipant.json:
Place the call:
Troubleshooting
Call connects but agent never speaks: Verify your dispatch rule includes roomConfig.agents with the correct agentName. Without this, the agent won’t be automatically dispatched to the room.
Audio quality issues: Check your Telnyx SIP connection settings and ensure proper codec configuration. See the Telnyx troubleshooting guide.
Pipecat Integration
Pipecat is an open-source framework for building voice and multimodal conversational AI agents. You can integrate Telnyx Media Streaming with Pipecat to enable phone calls to your voice agents that use AssemblyAI for speech recognition.
This guide covers both dial-in (users call your number) and dial-out (your bot calls users) functionality.
Prerequisites
- Telnyx account: Create an account and purchase phone numbers at telnyx.com
- Public server or tunnel: For dial-out, you’ll need a public-facing server or tunneling service like ngrok
- API keys: Get API keys for AssemblyAI, OpenAI (or other LLM), and your preferred TTS service
Install the required dependencies:
Set up your environment variables:
How it works
Dial-in flow:
- User calls your Telnyx number
- Telnyx executes your TeXML application which establishes a WebSocket connection
- Telnyx opens a WebSocket to your server with real-time audio and call metadata
- Your bot processes the audio using the Pipecat pipeline with AssemblyAI STT
- The bot responds with audio sent back to Telnyx over WebSocket
- Telnyx plays the audio to the caller in real-time
Dial-out flow:
- Your application triggers a dial-out via API
- Server initiates a Telnyx call using the Call Control API
- Telnyx establishes the call and opens a WebSocket connection
- Your bot joins the WebSocket and sets up the pipeline
- The recipient answers and is connected to your bot
- The bot handles the conversation with real-time audio streaming
Dial-in Setup
Step 1: Create TeXML application
Telnyx uses TeXML (Telnyx Extensible Markup Language) to control call flow. Create a TeXML application that establishes a WebSocket connection to your bot:
The bidirectionalMode="rtp" parameter enables real-time audio streaming in both directions.
Custom data with query parameters: You can pass custom data to your bot by adding query parameters to the WebSocket URL:
Step 2: Configure Telnyx phone number
- Go to the Telnyx Portal
- Navigate to Voice → Programmable Voice → TeXML Applications
- Create a new TeXML Application with your WebSocket URL
- Assign the TeXML Application to your phone number
Step 3: Build your bot
Here’s a complete dial-in bot using AssemblyAI for speech recognition:
See the complete dial-in example for full implementation details including server setup.
Dial-out Setup
Dial-out allows your bot to initiate calls to phone numbers using Telnyx’s outbound calling capabilities.
How dial-out works
- Your application triggers a dial-out (via API call or user action)
- Server initiates a Telnyx call using the Call Control API
- Telnyx establishes the call and opens a WebSocket connection
- Your bot joins the WebSocket and sets up the pipeline
- The recipient answers and is connected to your bot
- The bot handles the conversation with real-time audio streaming
Bot configuration for dial-out
The dial-out bot configuration is similar to dial-in. Telnyx automatically provides call information in the WebSocket messages:
The transport and pipeline configuration are identical to dial-in. See the complete dial-out example for full server implementation with outbound call creation.
Key Features
Audio format: Telnyx Media Streaming uses 8kHz mono audio with 16-bit PCM encoding. Configure your pipeline accordingly:
Automatic call termination: When you provide Telnyx API credentials to the TelnyxFrameSerializer, it automatically ends calls when your pipeline ends:
Built-in call information: Unlike other providers, Telnyx automatically includes caller information (to/from numbers) in the WebSocket messages, eliminating the need for custom webhook servers in basic dial-in scenarios.
Advanced Configuration
For production use cases, you can customize AssemblyAI’s turn detection and add keyterms for improved accuracy:
Turn detection options: AssemblyAI has built-in VAD and turn detection. You can either:
- Use AssemblyAI’s turn detection (recommended for best accuracy)
- Use Silero VAD by including
vad_analyzer=SileroVADAnalyzer()in the transport params
Keyterms: Add domain-specific terms to improve recognition accuracy for specialized vocabulary.