ChatAI is a Vietnamese voice assistant application built with Python. It enables computers to listen – analyze – and respond in natural conversations using a combination of technologies:
- 🎤 SpeechRecognition → captures and recognizes speech from the microphone.
- 🧠 Google Gemini API → generates intelligent, context-aware responses.
- 🔊 gTTS (Google Text-to-Speech) + pygame → converts text into speech and plays it back through speakers.
- Continuous listening with automatic microphone pause during audio playback → prevents self-listening feedback.
- Context-aware responses enriched with system information such as time, location, and IP address.
- Designed to serve as a foundation for conversational AI research, IoT/Smart Home integration, or educational tools.
chatAI.py→ Main program, implements the pipeline: Microphone → Speech Recognition → Gemini API → Response Generation → TTS → Speaker Output.requirements.txt→ Complete list of required Python dependencies.
- Python 3.11+ (Windows, Linux, or macOS).
- A working microphone and speaker.
- Stable internet connection.
- A valid API key from Google Gemini API (Google AI Studio).
python -m venv .venv
# Windows
.\.venv\Scripts\activate
# Linux/Mac
source .venv/bin/activatepip install -r requirements.txtImportant packages:
SpeechRecognition– voice recognition.gTTS,pygame– text-to-speech and playback.requests– API requests to Gemini and IP location service.PyAudio,sounddevice– microphone support.
Open chatAI.py and replace:
GEMINI_API_KEY = "#####################"with your actual Gemini API key.
python chatAI.pyIf setup is correct, the console will display:
🎙️ Listening continuously...
-
You say: "Xin chào"
-
Console output:
👤 User: Xin chào 🤖 Assistant: Hello, how can I help you today? -
The assistant will speak the response aloud.
-
If the microphone doesn’t work → check drivers or run:
python -m speech_recognition
-
If no audio is played → check speakers or test with:
python -m pygame.examples.aliens
-
Speech Input
speech_recognition.Recognizer+Microphone.- Noise adjustment with
adjust_for_ambient_noise. - Limits each utterance to ~6 seconds.
-
Gemini API Processing
- Prompt includes user speech + system info (time, location, IP).
- Response returned as plain text.
-
Text-to-Speech & Playback
- Response text →
gTTS→ temporary audio file. - Played with
pygame.mixer. - Microphone disabled while speaking (
listening = False), then re-enabled.
- Response text →
- Multi-language support (English, Japanese, etc.).
- Wake Word Detection (e.g., “Hey Assistant”).
- IoT/Smart Home integration (control lights, fans, appliances).
- GUI development with Tkinter or PyQt.
- Web service deployment (Flask, FastAPI).
This project is released under the MIT License, a permissive open-source license that allows:
- Full rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the software.
- Use in both personal and commercial projects.
The only requirement is to retain the original copyright notice and license in all copies.
© 2025 Trần Đăng Khoa
This software is provided “as is”, without any warranty of any kind, express or implied. The author is not liable for any claims, damages, or other liabilities that may arise from its use.