A minimal voice agent using Gemini Live API.
- Browser captures microphone audio.
- Backend creates a short-lived Gemini ephemeral token.
- Browser opens a Gemini Live WebSocket session.
- Audio streams to Gemini, model audio streams back.
- Transcript events are shown in the UI.
+------------------+ +----------------------+ +-------------------------+
| User Browser | | Node/Express Server | | Gemini Live API |
+------------------+ +----------------------+ +-------------------------+
| | |
| POST /api/gemini/live-token| |
|--------------------------->| |
| | create ephemeral token |
| |-------------------------------> |
| |<------------------------------- |
| | token |
|<---------------------------| |
| ephemeralToken+config | |
|
| WebSocket connect with access_token |
|--------------------------------------------------------------->|
|<---------------------------------------------------------------|
| setupComplete + streaming events |
|==================== audio + transcripts ======================>|
Gemini Live API is implemented over WebSockets (not direct native WebRTC in this app).
src/server.tsPOST /api/gemini/live-tokenfor ephemeral token provisioning.
src/client.ts- WebSocket connect/disconnect.
- Microphone capture, PCM downsampling (16k), stream send.
- PCM playback of model audio, transcript display.
public/index.html- Connect / Disconnect / Mute UI.
.env.example- Gemini env vars.
Returns:
ephemeralTokenmodelvoicesystemPrompt
Required:
GEMINI_API_KEY
Optional:
PORT(default3000)GEMINI_LIVE_MODEL(defaultgemini-3.1-flash-live-preview)GEMINI_VOICE(defaultKore)GEMINI_SYSTEM_PROMPTRATE_LIMIT_WINDOW_MS(default60000)RATE_LIMIT_MAX_REQUESTS(default10)
cp .env.example .env
# set GEMINI_API_KEY in .env
npm install
npm run devOpen http://localhost:3000 and click Connect.
npm run build
npm start- Build command:
npm run build - Start command:
npm start - Required env:
GEMINI_API_KEY
- If token creation fails: verify
GEMINI_API_KEY. - If token requests are rejected with
429: increaseRATE_LIMIT_MAX_REQUESTSor wait for the window reset. - If socket connect fails: confirm model name and key permissions.
- If no mic audio: allow browser microphone permission.
- If no sound playback: check browser output device / autoplay policy.
This is an MVP optimized for quick deployment. It does not yet include auth, billing controls, advanced observability, or telephony adapters.