A web-based voice assistant using the OpenAI Assistants API and SerpAPI to answer questions with real-time internet data.
- Voice input via Web Speech API (no extra library needed)
- Voice output via Web Speech Synthesis API
- Live internet search via SerpAPI (Google)
- Typing fallback if microphone is unavailable
- Proper async run polling (no recursive stack issues)
- Handles multiple tool calls in a single turn
- Node.js 18+
- An OpenAI account with API access
- A SerpAPI account (free tier available)
Go to platform.openai.com/assistants and create an assistant with this system prompt:
You're a general AI assistant that can help with anything. You're a voice
assistant, so keep your answers clear and concise. When the user asks about
current events or real-time data, use the getSearchResult function.
Add the following function tool:
{
"name": "getSearchResult",
"description": "Returns search results from Google for a given query.",
"parameters": {
"type": "object",
"properties": {
"query": {
"type": "string",
"description": "The search query"
}
},
"required": ["query"]
}
}Note: Pick a model that supports function calling (e.g.
gpt-4oorgpt-4-turbo).
git clone https://github.com/AdarshZolekar/AI-Voice-Assistant
cd AI-Voice-Assistant
npm install
cp .env.example .env
# Edit .env and fill in OPENAI_API_KEY, ASSISTANT_ID, SERPAPI_KEY
npm startOpen http://localhost:3000 in your browser.
├── index.js # Express server — thread management, run polling, tool dispatch
├── public/
│ └── index.html # Frontend — voice UI, chat bubbles, Web Speech API
├── package.json
├── example.env
└── README.md
User speaks / types
↓
POST /message → create thread message → start run
↓
Poll run status every 1.5s
↓
requires_action? → call getSearchResult(query) via SerpAPI → submit outputs
↓
completed? → fetch latest message → return to frontend
↓
Display text + speak aloud
- The Assistants API is in beta — occasional errors from OpenAI are expected.
- Web Speech API varies by browser; Chrome/Edge have the best support.
- SerpAPI free tier has a request limit per month.
This project is open-source under the MIT License.
Contributions are welcome!
-
Open an issue for bugs or feature requests
-
Submit a pull request for improvements.