◉GEMINI LABJP
●2.5 ROUTE — From today, 12/1, calls to gemini-2.5-pro and 2.5-flash are rerouted to newer models automatically●CLI 0.71.1 — Gemini CLI stable is still v0.71.1, with a 0.73 nightly published on 11/30●INTRO END — Introductory pricing for 3.8, 3.7 and 3.6 Flash ends on 12/31. 30 days left●VERTEX — Developers are asking how to run Gemini CLI with Vertex AI credentials●NEON — Gemini 4 Neon became generally available on 11/18 (paid tier only)●IMAGE TEXT — A new test shows text inside an image can sway Gemini's answer●2.5 ROUTE — From today, 12/1, calls to gemini-2.5-pro and 2.5-flash are rerouted to newer models automatically●CLI 0.71.1 — Gemini CLI stable is still v0.71.1, with a 0.73 nightly published on 11/30●INTRO END — Introductory pricing for 3.8, 3.7 and 3.6 Flash ends on 12/31. 30 days left●VERTEX — Developers are asking how to run Gemini CLI with Vertex AI credentials●NEON — Gemini 4 Neon became generally available on 11/18 (paid tier only)●IMAGE TEXT — A new test shows text inside an image can sway Gemini's answer
Articles/API / SDK
◈ API / SDK/2026-04-04Intermediate

Building Voice Agents with Gemini Live API: A Basics

Learn how to build real-time voice agents using Gemini Live API. From setup to implementation examples, this guide covers everything you need to get started.

Gemini Live API6Voice AgentReal-time AudioGemini Flash LiveAPI Development

The launch of Gemini Live API has transformed how AI agents interact with users. Moving beyond traditional text-based exchanges, developers can now create natural voice conversations with minimal latency. This shift significantly improves user experience and opens new possibilities for voice-driven applications.

Understanding Gemini Live API

Gemini Live API leverages Gemini Flash Live, Google's latest lightweight model optimized for real-time voice interactions.

Key Features

  • Real-time Processing: Processes incoming audio instantly with minimal delay
  • Natural Conversation: Recognizes vocal emotion and tone for more human-like responses
  • Low Latency: Edge-optimized processing ensures fast response times
  • Multi-turn Dialogue: Maintains conversation context across multiple exchanges

Gemini Flash Live is purpose-built for real-time scenarios, making it more efficient than standard Gemini models for voice applications.

Getting Started

1. Obtaining Your API Key

To use Gemini Live API, you'll need a Google API key.

Visit Google AI Studio and follow these steps:

  1. Click "Get API Key"
  2. Create or select a project
  3. Click "Create API Key"
  4. Copy the generated key
export GEMINI_API_KEY="YOUR_GEMINI_API_KEY"

2. Setting Up Your Environment

Here's a Node.js setup example:

npm init -y
npm install google-generative-ai dotenv

Basic Implementation

Minimal Voice Agent

This example demonstrates a voice agent that captures microphone input and sends it to Gemini Live API:

const { GoogleGenerativeAI } = require('@google/generative-ai');
require('dotenv').config();
 
const apiKey = process.env.GEMINI_API_KEY;
const genAI = new GoogleGenerativeAI(apiKey);
 
async function createVoiceAgent() {
  const model = genAI.getGenerativeModel({
    model: 'gemini-2.0-flash-live'
  });
 
  const session = model.startSession({
    generationConfig: {
      temperature: 0.7,
      topK: 40,
      topP: 0.95
    }
  });
 
  console.log('Voice agent initialized. Start speaking...');
 
  const audioData = Buffer.from('your_audio_bytes');
 
  try {
    const response = await session.sendMessage({
      inlineData: {
        mimeType: 'audio/webm',
        data: audioData.toString('base64')
      }
    });
 
    console.log('Agent response:');
    console.log(response.response.text());
 
  } catch (error) {
    console.error('An error occurred:', error);
  }
 
  await session.end();
}
 
createVoiceAgent();

Web Application Implementation

Here's how to capture voice input in a browser and send it to Gemini Live API:

<!DOCTYPE html>
<html>
<body>
  <button id="startBtn">Start</button>
  <button id="stopBtn">Stop</button>
  <div id="response"></div>
 
  <script>
    let mediaRecorder;
    let audioChunks = [];
 
    document.getElementById('startBtn').addEventListener('click', async () => {
      const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
      mediaRecorder = new MediaRecorder(stream);
 
      mediaRecorder.ondataavailable = (event) => {
        audioChunks.push(event.data);
      };
 
      mediaRecorder.onstop = async () => {
        const audioBlob = new Blob(audioChunks, { type: 'audio/webm' });
        await sendToGeminiAPI(audioBlob);
      };
 
      mediaRecorder.start();
    });
 
    document.getElementById('stopBtn').addEventListener('click', () => {
      mediaRecorder.stop();
    });
 
    async function sendToGeminiAPI(audioBlob) {
      const audioBase64 = await blobToBase64(audioBlob);
 
      const response = await fetch('/api/gemini-voice', {
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify({
          audio: audioBase64,
          mimeType: 'audio/webm'
        })
      });
 
      const data = await response.json();
      document.getElementById('response').innerText = data.reply;
    }
 
    function blobToBase64(blob) {
      return new Promise((resolve) => {
        const reader = new FileReader();
        reader.onloadend = () => {
          const base64 = reader.result.split(',')[1];
          resolve(base64);
        };
        reader.readAsDataURL(blob);
      });
    }
  </script>
</body>
</html>

Backend Implementation (Node.js + Express)

const express = require('express');
const { GoogleGenerativeAI } = require('@google/generative-ai');
require('dotenv').config();
 
const app = express();
app.use(express.json({ limit: '50mb' }));
 
const genAI = new GoogleGenerativeAI(process.env.GEMINI_API_KEY);
 
app.post('/api/gemini-voice', async (req, res) => {
  try {
    const { audio, mimeType } = req.body;
 
    const model = genAI.getGenerativeModel({
      model: 'gemini-2.0-flash-live'
    });
 
    const response = await model.generateContent({
      contents: [
        {
          role: 'user',
          parts: [
            {
              inlineData: {
                mimeType: mimeType,
                data: audio
              }
            }
          ]
        }
      ]
    });
 
    const reply = response.response.text();
    res.json({ reply });
 
  } catch (error) {
    console.error('Error:', error);
    res.status(500).json({ error: error.message });
  }
});
 
app.listen(3000, () => {
  console.log('Server running on port 3000');
});

Advanced Voice Agent Features

1. Multi-turn Conversation

Maintain session state across multiple exchanges:

const session = model.startSession();
 
const response1 = await session.sendMessage(message1);
const response2 = await session.sendMessage(message2);
 
await session.end();

2. Custom System Instructions

Control agent behavior with system prompts:

const model = genAI.getGenerativeModel({
  model: 'gemini-2.0-flash-live',
  systemInstruction: {
    parts: [
      {
        text: 'You are a helpful customer service agent.'
      }
    ]
  }
});

Building on the Dolice Labs apps as an indie developer, I found that with voice the silence matters more than cleverness. I return a quick acknowledgment while generating, reconnect immediately on a drop, and watch for the user starting to speak so I can interrupt my own playback — not talking over them is half of what makes it feel natural.

Wrapping up

Gemini Live API enables developers to create natural voice conversation experiences with AI agents. Start with the examples provided and customize them for your specific use case. With Gemini Flash Live's optimized performance and understanding of natural language, your users will enjoy seamless voice interactions.

Share

Thank You for Reading

Gemini Lab is ad-free, supported entirely by members like you. We publish practical guides daily with implementation code, benchmarks, and production-ready patterns. If you've found it useful, we'd love to have you on board.

  • ✦Copy-paste ready implementation code
  • ✦New advanced guides published daily
  • ✦$5/mo or $10 for lifetime access
View Membership →

If you found this article helpful, a small tip ($1.50) would mean a lot to us. Your support helps keep this site ad-free and covers server and hosting costs.

Related Articles

◈ API / SDK2026-11-14
When JSON Shapes Drift Through Gemini's OpenAI Compatibility Layer: Three Steps to response_json_schema Without Rewriting Callers
If your OpenAI SDK code points at Gemini and structured output seems ignored, here is how to check whether a schema is actually sent, and how to move to the Gemini SDK's response_json_schema while keeping the same function boundary.
◈ API / SDK2026-10-30
An 'API key expired' Error Doesn't Always Mean Expired. Check Which Key Is Actually Sent Before You Renew It
A 400 with API_KEY_INVALID from the Gemini API cannot tell you whether the key expired or something else is wrong. A small diagnostic script checks env-var precedence and stray quotes first, run here against dummy keys.
◈ API / SDK2026-10-30
My ADK Agent Never Ran and Said 'API key expired' — Reading the Reason Code Gave Me a Triage Order
When ADK returns 400 INVALID_ARGUMENT 'API key expired. Please renew the API key.' on every run, check this order before assuming the key expired: read the reason code, compare shell and .env keys by their last four characters, then test the key alone over REST.