GEMINI LABJP
NANOLITE — Nano Banana 2 Lite is here: Google's fastest and most cost-efficient Gemini Image model, made for running lightweight image generation cheaplyOMNIFLASH — Gemini Omni Flash is in public preview, a natively multimodal model that lets enterprises and developers build custom, dynamic video workflowsAGENTS — Managed Agents expand with background: true for async server-side runs and polling, remote MCP server integration, and refreshing credentials across interactionsMEMORY — The Memory Bank IngestEvents API is generally available, decoupling event ingestion from memory generation so you can stream content continuouslyTHROUGHPUT — Provisioned Throughput now lets you submit up to seven pending orders for the same model and regionDEPRECATE — Image generation models shut down on August 17, and the Grok 4.1 family on the Gemini Enterprise Agent Platform on August 20NANOLITE — Nano Banana 2 Lite is here: Google's fastest and most cost-efficient Gemini Image model, made for running lightweight image generation cheaplyOMNIFLASH — Gemini Omni Flash is in public preview, a natively multimodal model that lets enterprises and developers build custom, dynamic video workflowsAGENTS — Managed Agents expand with background: true for async server-side runs and polling, remote MCP server integration, and refreshing credentials across interactionsMEMORY — The Memory Bank IngestEvents API is generally available, decoupling event ingestion from memory generation so you can stream content continuouslyTHROUGHPUT — Provisioned Throughput now lets you submit up to seven pending orders for the same model and regionDEPRECATE — Image generation models shut down on August 17, and the Grok 4.1 family on the Gemini Enterprise Agent Platform on August 20
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-07-11
Stop Your Captions From Dancing: Splitting Live Translate Into Committed and Volatile Text
Pasting Gemini 3.5 Live Translate interim results straight to the screen makes captions flicker until they are unreadable. Here is a stabilizer that separates a committed prefix from a volatile tail and never rewinds, with working code and measured numbers.
API / SDK2026-07-05
Building Conversational Translation Into an App: Speech-to-Speech With the Live API
A design walkthrough for adding speech-to-speech conversational translation to an app with Gemini 3.5 Live Translate and the Live API, covering session lifetime, automatic language switching, latency budgets, and streaming cost, with working code.
API / SDK2026-06-16
Your Gemini Live API session forgets the conversation every time it reconnects — field notes on token refresh and session resumption
Why a Gemini Live API WebSocket drops the conversation and the user's in-flight speech on every reconnect, and how to close the gap with single-use ephemeral tokens, session resumption handles, and the goAway warning.
📚RECOMMENDED BOOKS
Build a Large Language Model (From Scratch)
Sebastian Raschka
LLM Dev
Prompt Engineering for LLMs
Berryman & Ziegler
Prompting
AI Engineering
Chip Huyen
AI Eng
* Contains affiliate links
See all →