Skip to main content
Glama
Sasidhar1826

AI Voice Assistant MCP Server

by Sasidhar1826

AI Voice Assistant with MCP Tool Calling

A fully free, end-to-end voice-enabled AI assistant built with Python.

Component

Technology

🧠 AI Brain

Google Gemini API (gemini-2.0-flash) β€” free tier

πŸŽ™οΈ Speech-to-Text

Google Web Speech API via SpeechRecognition β€” free

πŸ”Š Text-to-Speech

pyttsx3 (offline) β€” free

πŸ› οΈ Tool Calling

Model Context Protocol (MCP) β€” free

πŸ” Web Search

DuckDuckGo β€” free, no key needed

🌀️ Weather

wttr.in REST API β€” free, no key needed


Features

  • πŸŽ™οΈ Voice Input β€” speak naturally; the assistant understands you

  • πŸ”Š Voice Output β€” responses are read aloud via offline TTS

  • πŸ€– Gemini AI β€” context-aware, multi-turn conversation

  • πŸ› οΈ 7 MCP Tools available to the AI:

    1. Calculator β€” safe math expression evaluator

    2. Web Search β€” DuckDuckGo (no API key)

    3. Weather β€” real-time via wttr.in (no API key)

    4. Date/Time β€” current date and time

    5. Read File β€” read any local file

    6. Write File β€” write/append to a local file

    7. List Directory β€” browse local folders

  • πŸ’¬ Multi-turn memory β€” remembers conversation context

  • ⌨️ Text mode β€” works without a microphone (--text flag)


Related MCP server: Gemini MCP Chatbot

Prerequisites

  • Python 3.11+

  • A free Gemini API key β€” get one at https://aistudio.google.com/app/apikey

  • Internet connection (for speech recognition, Gemini API, and web tools)

  • Microphone (optional β€” text mode works without one)


Installation

1. Clone / download the project

# If using git:
git clone <your-repo-url>
cd "AI voice assistant"

# Or just open the folder in your terminal
cd "C:\Users\sasid\Downloads\AI voice assistant"
python -m venv .venv

# Windows:
.venv\Scripts\activate

# macOS / Linux:
source .venv/bin/activate

3. Install PyAudio (Windows β€” required for microphone)

PyAudio on Windows needs a pre-built binary. The easiest way:

pip install pipwin
pipwin install pyaudio

Or download the correct .whl from https://www.lfd.uci.edu/~gohlke/pythonlibs/#pyaudio and install with:

pip install PyAudio‑0.2.14‑cpXX‑cpXX‑win_amd64.whl

4. Install remaining dependencies

pip install -r requirements.txt

5. Set your Gemini API key

Option A β€” .env file (recommended):

copy .env.example .env
# Then open .env and replace "your_gemini_api_key_here" with your actual key

Option B β€” edit config.py directly:

Open config.py and change:

GEMINI_API_KEY: str = os.getenv("GEMINI_API_KEY", "YOUR_GEMINI_API_KEY_HERE")

to:

GEMINI_API_KEY: str = "your_actual_api_key"

Running

Voice mode (default β€” microphone + TTS)

python main.py

Text-only mode (no microphone needed)

python main.py --text

List available TTS voices

python main.py --list-voices

Example Interactions

You say

What happens

"What's the weather in Tokyo?"

Calls get_weather MCP tool β†’ speaks result

"Calculate 2 to the power of 32"

Calls calculator tool β†’ speaks 4294967296

"Search for the latest Python news"

Calls web_search β†’ summarises top results

"What day is today?"

Calls get_datetime β†’ speaks date & time

"Read the file notes.txt"

Calls read_file β†’ speaks file contents

"Write 'Hello World' to test.txt"

Calls write_file β†’ creates/updates file

"Reset conversation"

Clears chat history

"Goodbye" / "Exit"

Exits the assistant


Project Structure

AI voice assistant/
β”œβ”€β”€ main.py          # Entry point β€” CLI, banner, main loop
β”œβ”€β”€ assistant.py     # Gemini + MCP integration (agentic tool-call loop)
β”œβ”€β”€ speech.py        # SpeechRecognition (STT) + pyttsx3 (TTS)
β”œβ”€β”€ mcp_server.py    # MCP tool server with 7 built-in tools
β”œβ”€β”€ config.py        # All settings and API key placeholder
β”œβ”€β”€ requirements.txt # Python dependencies
β”œβ”€β”€ .env.example     # API key template
└── README.md        # This file

Customisation

Change the AI's personality

Edit SYSTEM_PROMPT in config.py.

Adjust microphone sensitivity

Edit MIC_ENERGY_THRESHOLD in config.py (lower = more sensitive).

Change TTS voice or speed

Edit TTS_RATE and TTS_VOICE_PREFERENCE in config.py. Run python main.py --list-voices to see available voice names.

Add more MCP tools

Open mcp_server.py, add a new function, then register it in list_tools() and call_tool().


Gemini Free Tier Limits

Limit

Value

Requests per minute

15

Tokens per day

1,000,000

Cost

$0

Get your key at: https://aistudio.google.com/app/apikey


Troubleshooting

"No module named 'pyaudio'" β†’ See PyAudio installation step above.

"Could not understand audio" β†’ Speak clearly; adjust MIC_ENERGY_THRESHOLD lower in config.py.

"Speech recognition service error" β†’ Check your internet connection (Google Web Speech API requires internet).

Gemini 429 / rate limit error β†’ You've hit the free tier limit. Wait a minute and try again.

Assistant doesn't speak / TTS silent β†’ Check system audio / volume. Try python main.py --list-voices to verify pyttsx3 works.


License

MIT β€” free to use, modify, and distribute.

Related MCP Connectors

Related MCP Servers