Skip to content

germankuber/voice-ai-assistant

Repository files navigation

🎙️ Voice AI Assistant

A real-time voice conversational assistant powered by OpenAI GPT-4 and Text-to-Speech.

✨ Features

  • 🗣️ Voice Input - Browser-based speech recognition (Spanish)
  • 🤖 AI Responses - GPT-4 powered conversational AI
  • 🔊 Voice Output - OpenAI TTS with 6 voice options
  • 💾 Persistent History - SQLite database for messages and users
  • Real-time Streaming - Streamed AI responses

🛠️ Tech Stack

Layer Technologies
Frontend React 19, TypeScript, Vite, Material-UI
Backend Express.js, TypeORM, SQLite
AI OpenAI GPT-4, OpenAI TTS
Validation Zod

📁 Project Structure

src/
├── server/                    # Backend
│   ├── core/errors/           # Custom error classes
│   ├── application/dtos/      # Request validation (Zod)
│   ├── infrastructure/        # Database entities
│   ├── presentation/          # Middlewares & responses
│   ├── services/              # Business logic
│   └── controllers/           # Route handlers
│
├── features/                  # Frontend (feature-based)
│   ├── auth/                  # Authentication context
│   ├── chat/                  # Chat logic & components
│   └── voice/                 # TTS & speech recognition
│
└── shared/                    # Shared utilities
    ├── api/                   # Centralized API client
    └── components/            # ErrorBoundary, etc.

🚀 Getting Started

Prerequisites

  • Node.js 18+
  • OpenAI API Key

Installation

git clone <repository-url>
cd voice-ai-app

# Frontend dependencies
npm install

# Backend dependencies
cd src/server && npm install

Configuration

Create .env in src/server/:

OPENAI_API_KEY=sk-your-api-key
PORT=3001
NODE_ENV=development

Running

# Terminal 1 - Backend
cd src/server && npm run dev

# Terminal 2 - Frontend
npm run dev

Open http://localhost:5173

📡 API Endpoints

Method Endpoint Description
POST /api/users Create/update user
POST /api/openai Send message, get AI response + audio
GET /api/messages/:userId Get user's message history
GET /api/voices List available TTS voices
GET /api/health Health check

Request Example

curl -X POST http://localhost:3001/api/openai \
  -H "Content-Type: application/json" \
  -d '{"text": "Hello", "voiceId": "echo", "userId": "user-1"}'

Response Format

{
  "success": true,
  "data": {
    "text": "AI response text",
    "audio": "base64-encoded-audio",
    "messageId": "uuid"
  },
  "timestamp": "2024-01-01T00:00:00.000Z"
}

🏗️ Architecture

┌─────────────┐     ┌─────────────┐     ┌─────────────┐
│   Browser   │────▶│   Express   │────▶│   OpenAI    │
│   (React)   │◀────│   Server    │◀────│   API       │
└─────────────┘     └──────┬──────┘     └─────────────┘
                           │
                    ┌──────▼──────┐
                    │   SQLite    │
                    │  (TypeORM)  │
                    └─────────────┘

🔒 Security

  • ✅ Input validation with Zod schemas
  • ✅ Rate limiting (100 req/15min, 20 req/min for chat)
  • ✅ Centralized error handling
  • ✅ Request logging

🎤 Available Voices

ID Name
alloy Alloy
echo Echo
fable Fable
onyx Onyx
nova Nova
shimmer Shimmer

📄 License

MIT

About

Real-time voice conversational assistant powered by OpenAI GPT-4 and TTS

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages