A minimal command-line app that streams microphone audio to the Gemini Live API and plays back the response in real time. This example is intended for local testing only, not for production use cases.
Note: Use headphones. This script uses the system default audio input and output, which often won't include echo cancellation. To prevent the model from interrupting itself, use headphones.
- Node.js 20+
- A Gemini API key (get one here)
- SoX (
brew install soxon macOS) — required by themicpackage
Install helpers for audio streaming. Additional system-level dependencies might be required (sox for Mac/Windows or ALSA for Linux). Refer to the speaker and mic docs for detailed installation steps.
npm install @google/genai mic speakerexport GEMINI_API_KEY="your-api-key"
npx tsx main.mtsYou should see "Connected to Gemini Live API" and "Microphone started. Speak now..." — talk into your mic and Gemini will respond with audio. Press Ctrl+C to quit.