Skip to main content

Advanced Real-Time Voice Chat System with Emotion Detection and AI Integration

Project description

SpaceVerse AI - Advanced Real-Time Voice Chat System

Python FastAPI OpenAI License

๐ŸŒŸ Overview

SpaceVerse AI is a cutting-edge real-time voice chat system that combines OpenAI's GPT-4o with advanced emotion detection, user preference analysis, and dynamic personalization. The system provides an intelligent, emotionally-aware conversational AI that adapts to users' communication styles and emotional states in real-time.

๐Ÿš€ Key Features

  • Real-Time Voice Communication: Seamless voice chat with OpenAI's GPT-4o
  • Facial Emotion Detection: Real-time emotion analysis using deep learning models
  • User Preference Learning: Dynamic adaptation to individual communication styles
  • Threat Detection: Advanced safety monitoring for crisis intervention
  • Multi-Language Support: Support for 12+ languages
  • Session Persistence: Intelligent session management with metadata tracking
  • WebSocket Architecture: Real-time bidirectional communication
  • Emotional Intelligence: AI responses that match detected emotions
  • Onboarding System: Dynamic question generation for personalization

๐Ÿ› ๏ธ Installation

Quick Installation (Recommended)

Install SpaceVerse AI directly from PyPI:

pip install spaceverseai

That's it! All dependencies will be installed automatically.

๐Ÿš€ Quick Start

Async Usage

import asyncio
from spaceverseai import SpaceverseAIClient, VoiceType, LanguageCode

async def main():
    async with SpaceverseAIClient() as client:
        # Check server health
        health = await client.health_check()
        print(f"Server status: {health.status}")
        
        # Connect to voice chat
        await client.connect_voice_chat()
        
        # Set preferences
        await client.set_user_settings(VoiceType.ALLOY, LanguageCode.ENGLISH)

if __name__ == "__main__":
    asyncio.run(main())

Synchronous Usage

from spaceverseai import SpaceverseAIClientSync, EmotionType

with SpaceverseAIClientSync() as client:
    health = client.health_check()
    print(f"Server health: {health.status}")
    
    client.connect_voice_chat()
    client.set_client_emotion(EmotionType.HAPPY)

Run Examples

# Run interactive examples
spaceverseai-demo --interactive

# Run all examples
spaceverseai-demo

๐Ÿ“‹ Prerequisites

System Requirements

  • Python: 3.8 or higher
  • RAM: Minimum 4GB (8GB recommended)
  • Storage: 2GB free space
  • Network: Stable internet connection
  • GPU: Optional (CUDA-compatible for faster emotion detection)

API Keys Required

  • OpenAI API Key: Required for GPT-4o access
  • Environment Variable: OPENAI_API_KEY

๐Ÿ—๏ธ Architecture

System Components

SpaceVerse AI
โ”œโ”€โ”€ ๐ŸŽค Voice Processing
โ”‚   โ”œโ”€โ”€ Real-time audio streaming
โ”‚   โ”œโ”€โ”€ Audio format conversion (PCM16)
โ”‚   โ””โ”€โ”€ Sample rate resampling (24kHz)
โ”œโ”€โ”€ ๐ŸŽญ Emotion Detection
โ”‚   โ”œโ”€โ”€ Facial emotion analysis
โ”‚   โ”œโ”€โ”€ Real-time image processing
โ”‚   โ””โ”€โ”€ Emotion-to-response mapping
โ”œโ”€โ”€ ๐Ÿง  AI Intelligence
โ”‚   โ”œโ”€โ”€ OpenAI GPT-4o integration
โ”‚   โ”œโ”€โ”€ User preference analysis
โ”‚   โ””โ”€โ”€ Threat detection system
โ”œโ”€โ”€ ๐Ÿ’พ Session Management
โ”‚   โ”œโ”€โ”€ Persistent session storage
โ”‚   โ”œโ”€โ”€ Metadata tracking
โ”‚   โ””โ”€โ”€ Event logging
โ””โ”€โ”€ ๐ŸŒ Web Interface
    โ”œโ”€โ”€ WebSocket connections
    โ”œโ”€โ”€ REST API endpoints
    โ””โ”€โ”€ Real-time updates

Technology Stack

  • Backend: FastAPI (Python)
  • AI Model: OpenAI GPT-4o Realtime
  • Emotion Detection: Hugging Face Transformers
  • Real-time Communication: WebSockets
  • Data Processing: NumPy, PyTorch
  • Image Processing: PIL (Pillow)
  • Concurrency: asyncio, ThreadPoolExecutor

๐ŸŽญ Emotion Detection System

Facial Emotion Processing

The system uses a pre-trained deep learning model to detect facial emotions in real-time:

# Emotion detection pipeline
processor = AutoImageProcessor.from_pretrained("dima806/facial_emotions_image_detection")
model = AutoModelForImageClassification.from_pretrained("dima806/facial_emotions_image_detection")

Emotion-to-Response Mapping

The AI adapts its communication style based on detected emotions:

Emotion Tone Speech Pattern Approach
Happy/Joy Joyful Quick High energy
Sad/Sadness Empathetic Soft Gentle
Angry/Anger Calm Measured Controlled
Fear/Fearful Reassuring Slow Protective
Surprise Engaging Normal Curious
Disgust Understanding Normal Accepting
Neutral Balanced Normal Moderate

๐Ÿ›ก๏ธ Safety and Threat Detection

Crisis Intervention System

The system includes advanced threat detection for user safety:

# Threat detection function for OpenAI
threat_detection_tool = {
    "type": "function",
    "name": "detect_threat_or_suicide",
    "description": "CRITICAL SAFETY FUNCTION: Detect suicidal intent, self-harm, or violence threats",
    "parameters": {
        "type": "object",
        "properties": {
            "contains_threat": {
                "type": "boolean",
                "description": "True if concerning content detected"
            }
        }
    }
}

Safety Features

  • Real-time Monitoring: Continuous analysis of user messages
  • Context Awareness: Distinguishes between academic discussion and genuine risk
  • Emotional Context: Considers facial and voice emotions in threat assessment
  • Crisis Resources: Provides immediate help when threats are detected
  • False Positive Prevention: Careful analysis to avoid unnecessary alerts

๐Ÿ”ง Configuration

Environment Variables

Variable Description Default Required
OPENAI_API_KEY OpenAI API key for GPT-4o access None โœ… Yes
LOG_LEVEL Logging level (DEBUG, INFO, WARNING, ERROR) INFO โŒ No
OPENAI_WS_URL OpenAI WebSocket URL GPT-4o Realtime โŒ No

Model Configuration

The application uses pre-trained models for emotion detection:

# Facial Emotion Detection Model
model = AutoModelForImageClassification.from_pretrained("dima806/facial_emotions_image_detection")
processor = AutoImageProcessor.from_pretrained("dima806/facial_emotions_image_detection")

Supported Emotions: happy, sad, angry, fearful, surprise, disgust, neutral

๐Ÿ“Š API Endpoints

Health and Status

GET /health

Get application health status and connection information.

Response:

{
  "status": "healthy",
  "message": "OpenAI Realtime Voice Chat API is running",
  "connections": {
    "voice_websockets": 2,
    "image_websockets": 1,
    "openai_connections": 2,
    "total_sessions": 2
  }
}

Session Management

GET /api/sessions

List all active sessions with metadata.

GET /api/session/{session_id}/status

Get comprehensive session status and configuration.

GET /api/session/{session_id}/history

Get session information (OpenAI manages conversation history).

GET /api/session/{session_id}/events

Get OpenAI event IDs tracked for the session.

Client Configuration

GET /api/client/{client_id}/emotion

Get current detected emotion for a client.

POST /api/client/{client_id}/emotion

Manually set detected emotion and trigger session update.

GET /api/client/{client_id}/onboarding-data

Get current onboarding data for a client.

POST /api/client/{client_id}/onboarding-data

Set onboarding data and trigger session update.

๐ŸŒ Multi-Language Support

Supported Languages

Language Code Voice Support Transcription
English en โœ… โœ…
Spanish es โœ… โœ…
French fr โœ… โœ…
German de โœ… โœ…
Italian it โœ… โœ…
Portuguese pt โœ… โœ…
Russian ru โœ… โœ…
Japanese ja โœ… โœ…
Korean ko โœ… โœ…
Chinese zh โœ… โœ…
Arabic ar โœ… โœ…
Hindi hi โœ… โœ…

๐Ÿค Contributing

Development Setup

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests for new features
  5. Submit a pull request

Code Style

  • Follow PEP 8 Python style guide
  • Add comprehensive docstrings
  • Include type hints
  • Write unit tests for new features

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ™ Acknowledgments

  • OpenAI: For providing the GPT-4o Realtime API
  • Hugging Face: For the emotion detection models
  • FastAPI: For the excellent web framework
  • Community: For feedback and contributions

๐Ÿ“ž Support

Getting Help

  • Documentation: This README and inline code comments
  • Issues: Create GitHub issues for bugs or feature requests
  • Discussions: Use GitHub Discussions for questions
  • Email: Contact the development team

Common Issues

Connection Problems

  • Check OpenAI API key is valid
  • Verify internet connection
  • Check firewall settings

Audio Issues

  • Ensure microphone permissions
  • Check audio format compatibility
  • Verify sample rate settings

Emotion Detection Issues

  • Ensure camera permissions
  • Check image quality
  • Verify model loading

SpaceVerse AI - Bringing intelligence and emotion to real-time conversations. ๐Ÿš€

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

spaceverseai-1.0.0.tar.gz (26.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

spaceverseai-1.0.0-py3-none-any.whl (24.7 kB view details)

Uploaded Python 3

File details

Details for the file spaceverseai-1.0.0.tar.gz.

File metadata

  • Download URL: spaceverseai-1.0.0.tar.gz
  • Upload date:
  • Size: 26.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.7

File hashes

Hashes for spaceverseai-1.0.0.tar.gz
Algorithm Hash digest
SHA256 cdfe4fae19b4e2a04c71af76ecc396c98fe7d43f6bb36dda930a3de98251d0bb
MD5 3b7968754f2a96e19803a0d95637ea21
BLAKE2b-256 c963968d2c3b8840cd8627ba330946a7ee57d08cc8eea76a9bfd4fbcfe16264b

See more details on using hashes here.

File details

Details for the file spaceverseai-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: spaceverseai-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 24.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.7

File hashes

Hashes for spaceverseai-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d9b13986eb07c979e9a7ef830c383d490694b4287ab94ef9b936b14a1bd66e5c
MD5 2f7cae010ff667f38e5025beb55824bc
BLAKE2b-256 da1da569c1449fe803af9e18a1ff9854ce30d254ff29b0646c52b58b417e2a62

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page