A telephone-based conversational agent built with Pipecat that connects to Twilio for voice calls.
- Telephone voice conversations powered by:
- Deepgram (STT)
- OpenAI (LLM)
- Cartesia (TTS)
- Voice activity detection with Silero
- FastAPI WebSocket connection with Twilio
- 8kHz audio sampling optimized for telephone calls
OPENAI_API_KEY
DEEPGRAM_API_KEY
CARTESIA_API_KEY
- Twilio account with Media Streams configured
Modify the system prompt in bot.py
:
messages = [
{
"role": "system",
"content": "You are Chatbot, a friendly, helpful robot..."
},
]
Update the voice ID in the TTS service:
tts = CartesiaTTSService(
api_key=os.getenv("CARTESIA_API_KEY"),
voice_id="79a125e8-cd45-4c13-8a67-188112f4dd22", # Change this
)
The pipeline is configured for telephone-quality audio (8kHz). If your Twilio configuration uses different parameters, adjust these values:
task = PipelineTask(
pipeline,
params=PipelineParams(
audio_in_sample_rate=8000, # Input sample rate
audio_out_sample_rate=8000, # Output sample rate
# Other parameters...
),
)
To connect this agent to Twilio:
-
Purchase a number from Twilio, if you haven't already
-
Collect your Pipecat Cloud organization name:
pcc organizations list
You'll use this information in the next step.
- Create a TwiML Bin:
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Connect>
<Stream url="wss://api.pipecat.daily.co/ws/twilio">
<Parameter name="_pipecatCloudServiceHost" value="AGENT_NAME.ORGANIZATION_NAME"/>
</Stream>
</Connect>
</Response>
where:
- AGENT_NAME is your agent's name (the name you used when deploying)
- ORGANIZATION_NAME is the value returned in the previous step
- Assign the TwiML Bin to your phone number:
- Select your number from the Twilio dashboard
- In the
Configure
tab, setA call comes in
toTwiML Bin
- Set
TwiML Bin
to the Bin you created in the previous step - Save your configuration
See the top-level README for deployment instructions.