# Project export: DriveSense AI

This document was generated by HackStack to give an AI agent context about a hackathon project. Sections are labeled with their provenance; content marked as truncated was cut to keep this document small.

## Project metadata

- Hackathon: Cal Hacks 11.0
- Tagline: Imagine a car that understands your emotions. Using Hume AI’s EVI, we create a smart, empathetic driving experience with mood-based adjustments, fatigue alerts, and personalized navigation.
- Devpost: https://devpost.com/software/drivesense-ai
- GitHub: https://github.com/Sri-H-G/DriveSense_AI
- Team: 1 GitHub contributor(s) — Sri-H-G (6 commits)

## Devpost submission (written by the team)

### Inspiration

The inspiration behind DriveSense AI came from the desire to make driving safer and more comfortable by addressing the emotional state of drivers. Long drives, stressful traffic, or fatigue can lead to accidents or road rage. I wanted to create a system that not only listens but understands the driver’s emotions, helping to reduce stress and enhance safety using Hume AI’s Empathic Voice Interface (EVI).

### What it does

DriveSense AI detects the driver’s mood in real-time through voice cues, adjusting the car’s environment accordingly. It can: -Adjust lighting and music to reduce stress. -Monitor for signs of fatigue or distraction and offer alerts or suggest autonomous driving. -Provide adaptive navigation, offering fast routes for stressed drivers or scenic ones for relaxed trips. -Control infotainment and vehicle settings hands-free, adjusting based on emotional intent.

### How we built it

I built DriveSense AI by integrating Hume AI’s EVI with existing vehicle systems for real-time voice analysis. The core components include: -Mood Detection and Response: Detects the driver’s emotional state and adjusts lighting, music, and environment settings. -Safety Monitoring: Analyzes speech patterns for signs of fatigue or distraction, issuing alerts or recommending autonomous driving. -Contextual Assistance: Provides proactive navigation suggestions based on the driver’s tone and offers voice-controlled hands-free interaction with vehicle systems.

### Challenges we ran into

Building the project alone posed several challenges: -Real-Time Processing: Ensuring that mood detection was fast and precise enough to trigger immediate adjustments. -System Integration: Seamlessly connecting EVI with the car’s navigation, media, and safety systems. -Mood Precision: Accurately differentiating between similar emotions, like stress and fatigue, required fine-tuning the AI models.

### Accomplishments we're proud of

I’m proud of creating a semi functional, real-time emotion detection system that enhances both the safety and comfort of drivers. DriveSense AI not only responds to voice commands but understands the emotional context behind them, offering a personalized and empathetic driving experience.

### What we learned

Through this project, I learned the immense potential of combining voice recognition with emotional intelligence. I gained hands-on experience with Hume AI’s EVI, system integration, and the technical complexities of creating a real-time, emotion-aware vehicle assistant.

### What's next

Next, I aim to further enhance DriveSense AI by: -Integrating it with smart city infrastructure for real-time traffic data and improved routing. -Expanding its learning capabilities to better personalize driver preferences over time. -Collaborating with automotive manufacturers to bring DriveSense AI into commercial vehicles, making emotionally aware cars a reality for everyone.

## README (from the GitHub repository)

No README available.

## Detected evidence (automated analysis)

Indexed codebase: 1 recognized source files, 2 KB.
- Python (language) — detected in the code
- React (technology) — claimed on Devpost, not found in the code

## Codebase structure (from repository index)

### Files (4 of 4)

```
.DS_Store
.gitignore
mood_detection.py
requirements.txt
```

### Dependencies

- requirements.txt: asyncio, httpx, hume, python-dotenv

### Recent commits (newest first)

- Removed env
- Checking the env leak
- Removed env
- Fixed the leak
- Fixed the leak
- Hume connection working

## Key source files (fetched from GitHub, selected and truncated for size)

### requirements.txt

```
hume
asyncio
httpx
python-dotenv
```

### mood_detection.py

```python
import os
import asyncio
import pyaudio
from dotenv import load_dotenv
from hume.client import AsyncHumeClient
from hume.empathic_voice.chat.socket_client import ChatConnectOptions
from hume import Stream

load_dotenv()

HUME_API_KEY = os.getenv("HUME_API_KEY")
HUME_SECRET_KEY= os.getenv("HUME_SECRET_KEY")
HUME_CONFIG_ID= os.getenv("HUME_CONFIG_ID")

print(f"HUME_API_KEY: {HUME_API_KEY}")
print(f"HUME_SECRET_KEY: {HUME_SECRET_KEY}")
print(f"HUME_CONFIG_ID: {HUME_CONFIG_ID}")

#Audio Settings: 
CHUNK = 1024
FORMAT = pyaudio.paInt16
CHANNELS = 1 
RATE = 16000

async def on_message(message):
    print ("MESSAGE:", message)

    if 'prosody' in message['models']:
        emotions = message['model']['prosody']['scores']
        print ("Detected EMOTIONS:", emotions)

        # if emotions.get("stress") > 0.5:
        #     print ("STRESS")
        # elif emotions.get("calm") > 0.5:
        #     print ("CALM")

    
        for emotion, score in emotions.items():
            print(f"{emotion}: {score:.2f}")

async def stream_audio_to_hume(stream):

    byte_stream = Stream.new()

    while True: 
        data = stream.read(CHUNK)
        await byte_stream.put(data)
        await asyncio.sleep(0.01)


async def connect_to_hume():
    client = AsyncHumeClient(api_key=HUME_API_KEY)

    options = ChatConnectOptions(config_id=HUME_CONFIG_ID, secret_key=HUME_SECRET_KEY)

    async with client.empathic_voice.chat.connect_with_callbacks(
        options=options, 
        on_message=on_message
    ) as socket: 
        print ("Connected to Hume")

        audio = pyaudio.PyAudio()
        stream = audio.open(format = FORMAT, 
                            channels=CHANNELS, 
                            rate=RATE, 
                            input=True,
                            frames_per_buffer=CHUNK)

        await stream_audio_to_hume(stream)

        await asyncio.sleep(5)

        stream.stop_stream()
        stream.close()
        audio.terminate()

if __name__== "__main__":
    asyncio.run(connect_to_hume())
    
```