realtime-voicechat-with-ai-wtrc-tts-stt

Public
Created Sep 22, 2025
5
Stars
0
Forks
5
Watchers
0
Issues

Repository Details

Primary Language
JavaScript
Repository Size 4 MB
Default Branch main
Created September 22, 2025
Last Update October 2, 2025
View on GitHub
Download ZIP

README.md

# 🎙️ AI Voice Chat Assistant ### *Real-time Voice & Text Conversations with AI* [![React](https://img.shields.io/badge/React-18.0-blue?logo=react)](https://reactjs.org/) [![Node.js](https://img.shields.io/badge/Node.js-18+-green?logo=node.js)](https://nodejs.org/) [![MongoDB](https://img.shields.io/badge/MongoDB-6.0-brightgreen?logo=mongodb)](https://www.mongodb.com/) [![OpenAI](https://img.shields.io/badge/OpenAI-GPT--3.5-orange?logo=openai)](https://openai.com/) [![License](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](CONTRIBUTING.md) **[Features](#-features)** • **[Demo](#-screenshots)** • **[Quick Start](#-quick-start)** • **[Documentation](#-api-documentation)** • **[Contributing](#-contributing)**
--- ## 📖 Overview A cutting-edge, full-stack AI chat application featuring **real-time voice & text communication**, powered by OpenAI GPT-3.5-turbo. Built with modern web technologies and following **clean code principles** with MVC architecture. ### 🎯 Perfect For - Learning full-stack development with AI integration - Building voice-enabled chatbots - Understanding WebRTC and real-time communication - Exploring modern React patterns and custom hooks - Implementing secure authentication flows --- ## ✨ Features
### 🤖 **AI Capabilities** - ✅ OpenAI GPT-3.5-turbo integration - ✅ Context-aware conversations - ✅ Natural language processing - ✅ Intelligent response generation ### 🎤 **Voice Features** - ✅ Real-time voice recording - ✅ Speech-to-text (Google Cloud) - ✅ Text-to-speech playback - ✅ WebRTC audio streaming ### 🔐 **Security & Auth** - ✅ JWT authentication - ✅ Secure password hashing - ✅ Protected API routes - ✅ Token-based sessions ### � **Modern UI/UX** - ✅ Cyber-futuristic design - ✅ Glassmorphism effects - ✅ Smooth animations (Framer Motion) - ✅ Fully responsive layout - ✅ Loading indicators - ✅ Typing animations
--- ## 🖼️ Screenshots
### 🏠 Home Page ![Home Page](docs/screenshots/home.png) *Futuristic landing page with animated background and smooth transitions* ### 💬 Chat Interface ![Chat Page](docs/screenshots/chat.png) *Real-time chat with AI assistant, voice controls, and typing animations* ### 🔑 Authentication ![Login & Register](docs/screenshots/auth.png) *Secure login and registration with beautiful glassmorphism design*
> **Note:** Screenshots are illustrative. The actual UI features neon gradients, particle effects, and cyber grid animations. --- --- ## 🏗️ Architecture ### 🎨 **Tech Stack**
#### **Frontend** ``` ├── React 18 ├── Vite ├── Tailwind CSS ├── Framer Motion ├── Socket.IO Client └── WebRTC API ``` #### **Backend** ``` ├── Node.js 18 ├── Express.js ├── MongoDB + Mongoose ├── Socket.IO ├── JWT ├── OpenAI API └── Google Cloud Speech ```
### 📂 **Project Structure**
Backend (MVC Pattern) ``` server/ ├── 📁 config/ # Application configuration │ ├── constants.js # App-wide constants │ ├── database.js # MongoDB connection │ └── env.js # Environment variables ├── 📁 controllers/ # Request handlers │ ├── authController.js # Authentication logic │ ├── chatController.js # Chat operations │ └── socketController.js # WebRTC signaling ├── 📁 services/ # Business logic │ ├── gptService.js # OpenAI integration │ ├── sttService.js # Speech-to-Text │ ├── ttsService.js # Text-to-Speech │ └── socketService.js # WebRTC signaling ├── 📁 middleware/ # Express middleware │ ├── auth.js # JWT verification │ └── errorHandler.js # Error handling ├── 📁 models/ # Database models │ └── User.js # User schema ├── 📁 routes/ # API routes │ ├── auth.js # Auth endpoints │ └── chat.js # Chat endpoints └── 📄 index.js # Main entry point ```
Frontend (Component-Based) ``` src/ ├── 📁 services/ # API & Business logic │ ├── apiService.js # HTTP requests │ ├── authService.js # Authentication │ ├── audioService.js # Audio recording/playback │ └── socketService.js # WebRTC & Socket.IO ├── 📁 hooks/ # Custom React hooks │ ├── useAuth.js # Authentication state │ ├── useChat.js # Chat functionality │ ├── useAudioRecording.js │ ├── useAudioPlayback.js │ └── useTypingAnimation.js ├── 📁 components/ # UI components │ ├── ChatPage.jsx # Main chat interface │ ├── LoginForm.jsx # Login form │ ├── RegisterForm.jsx # Registration form │ └── Home.jsx # Landing page ├── 📁 react-bits/ # Reusable UI components │ └── index.jsx # Card, Button, Input, etc. └── 📄 App.jsx # Main app component ```
### 🔄 **Data Flow** ```mermaid graph LR A[User] -->|Text/Voice| B[Frontend] B -->|HTTP/WS| C[Backend API] C -->|Query| D[OpenAI GPT] C -->|Store| E[MongoDB] D -->|Response| C C -->|TTS| F[Google Cloud] F -->|Audio| C C -->|Data| B B -->|Render| A ``` --- --- ## 🚀 Quick Start ### 📋 Prerequisites Before you begin, ensure you have: ```bash ✓ Node.js 18+ installed ✓ MongoDB running (Docker or local) ✓ OpenAI API Key ✓ Google Cloud credentials (optional, for voice features) ``` ### ⚡ Installation #### 1️⃣ **Clone the Repository** ```bash git clone https://github.com/canuzlas/realtime-voicechat-with-ai-wtrc-tts-stt.git cd realtime-voicechat-with-ai-wtrc-tts-stt ``` #### 2️⃣ **Backend Setup** ```bash cd server # Copy environment file cp .env.example .env # Install dependencies npm install # Edit .env and add your credentials: # - MONGODB_URI # - JWT_SECRET # - OPENAI_API_KEY (required) # - GOOGLE_APPLICATION_CREDENTIALS (optional) ``` #### 3️⃣ **Frontend Setup** ```bash cd .. # Copy environment file cp .env.example .env # Install dependencies npm install # Edit .env and set: # VITE_API_URL=http://localhost:3000 ``` #### 4️⃣ **Start with Docker** 🐳 *(Recommended)* ```bash cd server docker compose up -d ``` This starts MongoDB and the backend server. Then start the frontend: ```bash cd .. npm run dev ``` ✨ **Open** [http://localhost:5173](http://localhost:5173) #### 5️⃣ **Or Run Locally** ```bash # Terminal 1 - MongoDB docker run -d -p 27017:27017 --name mongodb mongo:6.0 # Terminal 2 - Backend cd server npm start # Terminal 3 - Frontend npm run dev ``` --- ## 🔑 Environment Variables ### Backend (`server/.env`) | Variable | Required | Description | Example | |----------|----------|-------------|---------| | `PORT` | No | Server port | `3000` | | `MONGODB_URI` | Yes | MongoDB connection string | `mongodb://localhost:27017/voice-chat` | | `JWT_SECRET` | Yes | Secret for JWT signing | `your-super-secret-key-here` | | `OPENAI_API_KEY` | Yes | OpenAI API key | `sk-...` | | `GOOGLE_APPLICATION_CREDENTIALS` | No | Path to Google Cloud credentials | `./google-credentials.json` | | `NODE_ENV` | No | Environment | `development` or `production` | ### Frontend (`.env`) | Variable | Required | Description | Example | |----------|----------|-------------|---------| | `VITE_API_URL` | Yes | Backend API URL | `http://localhost:3000` | > 💡 **Tip:** Use `openssl rand -base64 32` to generate a secure JWT_SECRET --- --- ## 📡 API Documentation ### 🔐 **Authentication Endpoints** #### Register User ```http POST /auth/register Content-Type: application/json { "name": "John Doe", "email": "john@example.com", "password": "securepass123" } ``` #### Login ```http POST /auth/login Content-Type: application/json { "email": "john@example.com", "password": "securepass123" } ``` **Response:** ```json { "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...", "user": { "id": "507f1f77bcf86cd799439011", "name": "John Doe", "email": "john@example.com" } } ``` ### � **Chat Endpoints** #### Send Text Message ```http POST /chat/message Authorization: Bearer Content-Type: application/json { "message": "Hello, AI assistant!" } ``` #### Send Voice Message ```http POST /chat/voice Authorization: Bearer Content-Type: multipart/form-data audio:

Quick Setup & Commands

Clone Repository

HTTPS
git clone https://github.com/canuzlas/realtime-voicechat-with-ai-wtrc-tts-stt.git
SSH
git clone git@github.com:canuzlas/realtime-voicechat-with-ai-wtrc-tts-stt.git

Essential Commands

Navigate to project
cd realtime-voicechat-with-ai-wtrc-tts-stt
Install dependencies
npm install
Start development
npm run dev

Related Repositories