- Add SpatialChatAudio component with distance-based volume rolloff - Each agent gets distinct tone (freq + waveform) - Stereo panning based on relative position to camera - HRTF PannerNode support for voice chat streams - Integrate with addChatMessage for spatial notifications - Tests + docs included
1.9 KiB
1.9 KiB
Spatial Chat Audio — 3D Audio for Chat Messages
Refs: the-nexus #1544
Overview
Adds spatial awareness to chat notifications so nearby users/agents sound louder. Volume scales with avatar distance from the camera.
Features
Chat Notification Sounds
- Each agent has a distinct tone (frequency + waveform)
- Volume decreases with distance (inverse rolloff)
- Stereo panning based on relative position to camera
- Sounds auto-cleanup after playback
3D Positional Voice (WebRTC-ready)
createVoiceSource()returns a PannerNode for real voice streams- HRTF panning model for realistic 3D positioning
- Update position in real-time as avatars move
Configurable Parameters
maxHearingDistance— max distance to hear sounds (default: 40)refDistance— full volume within this range (default: 5)rolloffFactor— volume falloff curve (default: 1.5)baseVolume— master volume cap (default: 0.3)
Usage
import { SpatialChatAudio } from './nexus/components/spatial-chat-audio.js';
// Initialize with camera
SpatialChatAudio.init(camera);
// Set max hearing distance
SpatialChatAudio.setMaxHearingDistance(50);
// Play a chat sound when a message arrives
// position = avatar/agent position in 3D world
SpatialChatAudio.playChatSound('timmy', agentPosition);
// For voice chat: create a persistent 3D source
const voice = SpatialChatAudio.createVoiceSource('user', avatarPosition);
// Update as avatar moves
voice.updatePosition(newPosition);
// Cleanup when disconnected
voice.destroy();
Agent Sound Profiles
| Agent | Frequency | Waveform |
|---|---|---|
| timmy | 440 Hz | sine |
| user | 523 Hz | sine |
| system | 330 Hz | triangle |
| kimi | 659 Hz | sine |
| claude | 392 Hz | sine |
| grok | 587 Hz | triangle |
| gemini | 494 Hz | sine |
Testing
node tests/test_spatial_chat_audio.js