---
title: "How to Build a Gemini Live Voice Agent with Twilio Agent Connect and Python"
description: "Phone audio differs from local microphone audio, requiring a translation layer between Twilio and Gemini Live. This tutorial builds a Python appointment concierge that connects Twilio Programmable Voice to the Gemini Live API through a custom Twilio Agent Connect provider. The provider converts 8 kHz μ-law phone audio to 16 kHz PCM for Gemini and 24 kHz Gemini output back to 8 kHz μ-law for Twilio. The agent handles interruptions, calls Python tools for appointment availability and booking, streams a live transcript, and supports outbound calls. The project uses twilio-agent-connect[server] 2.4, the google-genai Python SDK, FastAPI, and the gemini-3.8-live model as of October 2026."
---

# How to Build a Gemini Live Voice Agent with Twilio Agent Connect and Python

[Twilio](https://yomu.fyi/company/twilio) · Rishab Kumar · Nov 24, 2026

**Type:** Tutorial

## Summary

Phone audio differs from local microphone audio, requiring a translation layer between Twilio and Gemini Live. This tutorial builds a Python appointment concierge that connects Twilio Programmable Voice to the Gemini Live API through a custom Twilio Agent Connect provider. The provider converts 8 kHz μ-law phone audio to 16 kHz PCM for Gemini and 24 kHz Gemini output back to 8 kHz μ-law for Twilio. The agent handles interruptions, calls Python tools for appointment availability and booking, streams a live transcript, and supports outbound calls. The project uses twilio-agent-connect\[server\] 2.4, the google-genai Python SDK, FastAPI, and the gemini-3.8-live model as of October 2026.

## Context

Phone audio differs from local microphone audio; Twilio Media Streams sends base64-encoded 8 kHz μ-law, while Gemini Live expects 16 kHz PCM input and outputs 24 kHz PCM. A custom provider bridges these formats and manages per-call state.

## Approach / What changed

Build a Python appointment concierge that connects Twilio Programmable Voice to the Gemini Live API through a custom Twilio Agent Connect provider. The provider translates 8 kHz μ-law phone audio to 16 kHz PCM for Gemini and 24 kHz Gemini output back to 8 kHz μ-law for Twilio, handles interruptions, executes Python tools, streams a transcript, and supports outbound calls.

## Takeaways

- Twilio Media Streams sends phone audio as base64-encoded 8 kHz μ-law; Gemini Live expects 16 kHz PCM input and outputs 24 kHz PCM, requiring a custom audio bridge.
- The custom GeminiLiveProvider extends TAC’s MediaStreamsProviderConfig and creates one Gemini Live session and one audio bridge per call to prevent state leakage between callers.
- The same provider supports outbound calls by reusing the audio bridge and tools; pass an E.164-formatted destination with the –to flag to initiate an outbound conversation.

## FAQ

### Why does the phone ring but I hear silence?

Confirm the webhook uses POST, the public hostname in .env matches the active tunnel, and welcome\_instruction is configured. Open /health through the public URL to confirm the tunnel can reach the app.

### Why does the WebSocket connect and immediately close?

Inspect the server log for a media-format validation error. Twilio Media Streams should report audio/x-mulaw, an 8,000 Hz sample rate, and one channel.

### Why does audio sound choppy or too fast?

Make sure μ-law bytes are decoded before resampling, keep the sample-rate converter state between chunks, and send complete 20-millisecond output frames. Treating μ-law as PCM produces noise rather than speech.

**Tags:** [Agent Connect](https://yomu.fyi/topic/agent-connect), [Gemini](https://yomu.fyi/topic/gemini), [Python](https://yomu.fyi/topic/python), [Twilio](https://yomu.fyi/topic/twilio), [Voice AI](https://yomu.fyi/topic/voice-ai)

- Source: [Twilio](https://www.twilio.com/en-us/blog/developers/tutorials/build-gemini-live-voice-agent-twilio-connect-python)
- Source URL: https://www.twilio.com/en-us/blog/developers/tutorials/build-gemini-live-voice-agent-twilio-connect-python
- Ingested by Yomu: 2026-12-01T00:00:21.274Z

[Read original post](https://www.twilio.com/en-us/blog/developers/tutorials/build-gemini-live-voice-agent-twilio-connect-python)
