Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🎙️ ChatAI – Vietnamese Voice Assistant

📖 Introduction

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.

Key Features

  • 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.

📂 Project Structure

  • 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.

⚙️ Installation

1. Requirements

  • 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).

2. Create a Virtual Environment

python -m venv .venv
# Windows
.\.venv\Scripts\activate
# Linux/Mac
source .venv/bin/activate

3. Install Dependencies

pip install -r requirements.txt

Important packages:

  • SpeechRecognition – voice recognition.
  • gTTS, pygame – text-to-speech and playback.
  • requests – API requests to Gemini and IP location service.
  • PyAudio, sounddevice – microphone support.

🚀 Usage

1. Add Your API Key

Open chatAI.py and replace:

GEMINI_API_KEY = "#####################"

with your actual Gemini API key.

2. Run the Application

python chatAI.py

If setup is correct, the console will display:

🎙️ Listening continuously...

3. Try a Conversation

  • 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.

4. Troubleshooting Devices

  • 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

🎥 Demo

▶️ Watch Demo Video


🧩 Technical Workflow

  1. Speech Input

    • speech_recognition.Recognizer + Microphone.
    • Noise adjustment with adjust_for_ambient_noise.
    • Limits each utterance to ~6 seconds.
  2. Gemini API Processing

    • Prompt includes user speech + system info (time, location, IP).
    • Response returned as plain text.
  3. Text-to-Speech & Playback

    • Response text → gTTS → temporary audio file.
    • Played with pygame.mixer.
    • Microphone disabled while speaking (listening = False), then re-enabled.

🔬 Future Development

  • 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).

📜 License

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.

About

A Python-based Vietnamese Voice Assistant powered by Google Gemini API.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages