Hackathon Category: Reinventing the Wheel β Active Drowsiness Prevention Tracks: βοΈ Best Use of Snowflake | ποΈ Best Use of ElevenLabs
The "Reinvention": Traditional drowsiness detection is reactive (beeps when your eyes close) and passive. CogPilot is preventative and activeβit predicts monotony fatigue using a hybrid risk model (Math + ML) and intervenes with personalized conversational AI to keep the driver's brain engaged before they fall asleep.
CogPilot is a full-stack Android Automotive system that prevents driver drowsiness by:
- Monitoring real-time vehicle telemetry (CarHardware chassis speed, heading, GPS) and live voice acoustics (MicrophoneAnalyzer).
- Predicting drowsiness risk using a 50/50 Blended Risk Engine (Deterministic Math + ONNX Random Forest).
- Intervening with AI-generated cognitive stimuli via ElevenLabs Real-Time Conversational SDK.
- Engaging the driver uniquely based on personalized Snowflake driver profiles and semantic memory.
- β Real-Time ElevenLabs Client Tools - AI accesses Google Maps, live driving status, and judges driver attention.
- β Concurrent Audio Capture - Runs ONNX ML models on the mic stream simultaneously with the active ElevenLabs voice call.
- β
Snowflake Semantic Memory - Embeds transcripts via Cortex (
snowflake-arctic-embed-m) for long-term vector recall. - β
Snowflake Cortex LLM -
CORTEX.COMPLETE('snowflake-arctic')for summarizing trips andCORTEX.SENTIMENTfor emotional analysis. - β Direct Snowflake JDBC - Android talks directly to the warehouse, removing middleman backend latency.
- β Distraction-Optimized UI - Material Design 3 interface for Android Auto, strictly complying with Car App Library guidelines.
- β Acoustic Signal Processing - Custom Kotlin FFT extracts 29 audio features (ZCR, RMSE, Spectral Centroid) live.
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Android Automotive App (Kotlin + Material 3) β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β VoiceAgentService (ElevenLabs Conversational SDK) β β
β β ββ Client Tools (Google Maps, Risk Status, Attention Judge) β β
β β ββ WebSocket Hooks (Speech Pace WPS, Response Latency) β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€ β
β β RiskDecisionEngine (50/50 Blended Detection) β β
β β ββ Deterministic: Speed Variance + Time + Circadian + Traffic β β
β β ββ ONNX Runtime: Random Forest Acoustic Classifier β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€ β
β β MicrophoneAnalyzer (Concurrent Audio Capture API 29+) β β
β β ββ AudioFeatureExtractor (FFT, Spectral Analysis, 29 Features) β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β JDBC β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββββββββββββββββββββββββββββββββ
β Snowflake Cloud Data Platform β
β βββββββββββββββββββββββββββββββββββββββββββββ β
β β DRIVER_LOGS (5s Telemetry, High Volume) β β
β β TRIP_SUMMARIES (Arctic Generated) β β
β β CONVERSATION_MEMORY (Embedded Vectors) β β
β β USER_PROFILES (Persuasion Levers) β β
β βββββββββββββββββββββββββββββββββββββββββββββ β
β β
β CORTEX APIs: β
β ββ VECTOR_COSINE_SIMILARITY() β β
β ββ CORTEX.SENTIMENT() β β
β ββ CORTEX.EMBED_TEXT_768() β β
β ββ CORTEX.COMPLETE('snowflake-arctic') β β
βββββββββββββββββββββββββββββββββββββββββββββββββββ
CogPilot utilizes the ElevenLabs Real-Time Conversational SDK (0.7.2) to transform a voice agent into a high-precision car co-pilot, possessing true situational awareness.
The agent isn't just speaking; it's viewing the car's state. We implemented a sophisticated client-tool registry:
get_driving_status: Real-time extraction of vehicle speed, road type (Highway/Urban), and traffic density.search_nearby_places: Integration with Google Maps Places API. The agent can search for "rest areas" or "coffee" within a 10km radius, calculate straight-line distances in real-time using Haversine formulas, and present options verbally.update_agentic_attention_score: The agent acts as a subjective judge. During the conversation, it explicitly evaluates the driver's coherence and updates their global risk score via this tool.search_past_conversations: Allows the AI to query Snowflake's vector database to recall past topics of discussion.
We hooked directly into the ElevenLabs WebSocket onMessage stream (specifically user_transcript events) to derive real-time cognitive metrics:
- Speech Pace (WPS): Dynamically calculated Words-Per-Second. A drop in speech pace triggers a fatigue penalty.
- Response Latency Histogram: Tracks the precise millisecond delta between the agent finishing speech and the driver starting. Increasing latency trends are treated as high-priority cognitive load signals.
- Vocal Energy Mapping: Monitors VAD (Voice Activity Detection) levels to detect slurring or volume drops.
To eliminate AI "thinking" time at session start, we pre-inject live driving telemetry (Speed, Traffic, Circadian Window, aggregated driving hours) and calendar events directly into ElevenLabs dynamicVariables. The agent wakes up already knowing exactly where you are, how tired you feel, and your upcoming schedule.
CogPilot uses Snowflake not just as a telemetry sink, but as a real-time memory and reasoning engine.
CogPilot doesn't forget. We built a complete vector-based memory system directly in Snowflake:
- Embedding Generation: At the end of every trip, raw timed-conversation transcripts are vectorized using
SNOWFLAKE.CORTEX.EMBED_TEXT_768. - Vector Storage: Resulting embeddings are saved to the
CONVERSATION_MEMORYtable alongside the driver ID. - Semantic Retrieval: Drivers can ask, "What did we talk about last time I was this tired?" The AI invokes the
search_past_conversationstool, which executes aVECTOR_COSINE_SIMILARITYscan across years of driving history to retrieve relevant context.
- Arctic LLM Summarization: Every driving session is summarized using the
snowflake-arcticmodel. These summaries condense minutes of spoken dialogue into actionable driver insights saved to theTRIP_SUMMARIEStable, which primes the agent for the next trip. - Sentiment Analysis: Driver utterances are passed through
CORTEX.SENTIMENTto detect frustration or anomalies, allowing the agent to adapt its tone or escalate to a high-risk warning.
Driver profiles are managed as Snowflake records. The AI adapts its "intervention style" based on columns such as EFFECTIVE_LEVERS (e.g., uses metrics, prefers analogies) and REJECTION_PATTERNS. Marta gets a direct, metrics-driven approach, while Ana gets thoughtful, story-based interactions.
The core "Reinvention" is replacing reactive camera-based detection (which fails for sunglasses and night driving) with a 50/50 Blended Risk Engine that fuses deterministic physics with live Acoustic Machine Learning.
- Monotony Factor: Calculated via rolling standard deviation of vehicle speed. High speed + low variance = high monotony (highway hypnosis).
- Circadian Window: Time-aware weight mapping. The system inherently increases base risk during the known danger window of 2 AM - 5 AM.
- Duration Multiplier: Logarithmic fatigue accumulation ($D(t) = 0.3 \cdot \ln(1+t)/\ln(6)$) based on continuous driving time.
-
Telemetry Priority: Utilizes the
CarHardwareAPI for direct chassis speed, falling back to OS GPS only if the vehicle signal is stale.
We integrated a Random Forest drowsiness classifier converted to ONNX, analyzing the driver's voice while they talk to ElevenLabs.
- Concurrent Audio Capture: On Android 10+ (API 29), we use the
VOICE_RECOGNITIONaudio source. This bypasses Android's single-mic limitation, allowing CogPilot'sMicrophoneAnalyzerloop to capture raw PCM audio without silencing the active ElevenLabs WebRTC session. - Acoustic Feature Extraction: Implemented a custom complete Kotlin Audio Processing pipeline that performs real-time FFT (Fast Fourier Transform). It extracts 29 distinct features used by the model: Spectral Centroid, Zero Crossing Rate (ZCR), Root Mean Square Energy (RMSE), and Frequency Band Energy.
- Blended Score: The final score is a literal average:
(0.5 * MathModel) + (0.5 * OnnxProbability).
- Risk scores are mapped to the Karolinska Sleepiness Scale (1-9), the clinical standard for fatigue research.
-
Logarithmic Suppression Formula: Interventions are spaced using a suppression multiplier
$S(t) = \ln(1+t)/\ln(61)$ . This enforces strict cooldowns (minimum 1 minute between check-ins) to ensure CogPilot remains a helpful partner, not a nagging distraction.
CREATE TABLE DRIVER_LOGS (
id INTEGER AUTOINCREMENT,
timestamp BIGINT NOT NULL,
speed FLOAT NOT NULL,
heading FLOAT NOT NULL,
latitude FLOAT NOT NULL,
longitude FLOAT NOT NULL,
risk_score FLOAT,
created_at TIMESTAMP_NTZ DEFAULT CURRENT_TIMESTAMP(),
PRIMARY KEY (id)
);
CREATE TABLE USER_PROFILE (
driver_id VARCHAR PRIMARY KEY,
name VARCHAR,
effective_levers VARCHAR, -- E.g. "metrics, science"
rejection_pattern VARCHAR,
sleep_pattern VARCHAR
);
CREATE TABLE CONVERSATION_MEMORY (
id INTEGER AUTOINCREMENT,
driver_id VARCHAR,
raw_transcript VARCHAR,
embedding VECTOR(FLOAT, 768), -- Cortex Embedded
created_at TIMESTAMP_NTZ DEFAULT CURRENT_TIMESTAMP()
);
CREATE TABLE TRIP_SUMMARIES (
driver_id VARCHAR,
summary_text VARCHAR, -- Snowflake Arctic Output
created_at TIMESTAMP_NTZ
);- MediaBrowserService Integration: Shifted the app's automotive category to
Media. CogPilot appears as a native Media App on Android Automotive head units. - Native Playback Resumption: The agent broadcasts a standard
KEYCODE_MEDIA_PLAYintent instantly when the interaction ends, gracefully resuming whatever background media (Spotify, Podcasts) was previously playing. - Headless Startup Support: Refined the service architecture to initialize and verify credentials in the background completely headless, fulfilling strict Android Auto guidelines.
- Explicit Mathematical UI: Designed the Android Auto media player subtitle to render the exact underlying risk decision mathematics instead of abstract concepts. It displays:
Base: 0.12 + Env: 0.05 | Pace: 2.5wps | Agent: 0.50 | ONNX: 0.10 = Total Risk - Distraction Optimized: All car-facing XML and Compose components are explicitly tagged
distractionOptimizedfor safety compliance, favoring high-contrast dark modes and minimal glance times.
- Android Studio Giraffe or later
- JDK 11+
- Android SDK 34+
- Snowflake account (Account URL, User/Pass, WH, DB)
- ElevenLabs API Key & Agent ID
- Google Maps SDK Key
Update the following keys in your environment or directly in the respective Manager classes:
app/src/main/java/fyi/acmc/cogpilot/SnowflakeManager.kt-> Set JDBC URL and credentials.app/src/main/java/fyi/acmc/cogpilot/GoogleMapsManager.kt-> Set Google Maps API Key.app/src/main/java/fyi/acmc/cogpilot/VoiceAgentService.kt-> Set ElevenLabs Agent ID.
# Clone
cd /Users/acmc/cogpilot
# Build APK
./gradlew build
# Install on Emulator
./gradlew installDebug
# Start Headless
adb shell am start -n fyi.acmc.cogpilot/.MainActivitySince this is a sideloaded debug build, Android Auto will hide CogPilot by default.
- Open Android Auto Settings: Go to Settings -> Apps -> Android Auto -> Additional settings in the app.
- Enable Developer Mode: Scroll to the bottom and tap Version 10 times.
- Enable Unknown Sources: Tap the three-dot menu (top right) -> Developer settings -> Check Unknown sources.
- Restart: Disconnect from the car and restart your phone.
Watch these tags during a drive to see the system in action:
LocationCapture: Polls GPS/chassis speed every 5 seconds.RiskDecisionEngine: Outputs the blended 50/50 KSS score.MicrophoneAnalyzer:ποΈ Real-time audio capture started (Concurrent Mode)followed byπ€ ONNX Model Inference Result: 0.35every 5 seconds.VoiceAgentService: Shows websocket parsing forWPSandLatency, and displays all Tool Calls (e.g.,π’ Agent requested get_driving_status).
Built with β€οΈ for CrimsonCode Hackathon 2026 "CogPilot: Predicting fatigue, not just detecting it. Powered by Snowflake and ElevenLabs."