๐ฏ Overview
The freifick.net sound design system provides subtle, non-intrusive audio feedback for user interactions across the site. All sounds are:
- Opt-in only โ disabled by default, enabled via Settings or the ๐ sound button
- No autoplay โ sounds only play in response to user gestures (click, hover, keyboard)
- WebAudio synthesized โ no audio files, all sounds generated in-browser via Web Audio API
- Master volume control โ global volume slider in Settings (0-100%)
- Reduced motion aware โ automatically disabled when
prefers-reduced-motion: reduceis set - Accessible โ keyboard-triggered sounds, respect for system preferences, ARIA labels
- Performant โ lazy AudioContext initialization, shared context, minimal overhead
Current status: checkingโฆ
๐ต Sound Catalog
All 12 UI sounds with descriptions and categories. Click any sound to preview it (requires sound enabled).
๐งช Interactive Demo
Try the sounds in action. Hover over buttons, click them, toggle switches โ hear the subtle feedback.
Waveform visualizer โ shows the sound wave in real-time
โ๏ธ Implementation Details
Architecture
site/js/ui-sounds-rules.jsโ Pure sound definitions (12 sounds, categories, play functions)site/js/ui-sounds.jsโ DOM wiring (attaches sounds to interactive elements)site/slop.jsโ Core engine (global settings, AudioContext management,--slop-sound-volumeCSS property)site/js/settings.jsโ Settings page wiring (sound toggle, volume slider)
AudioContext Management
// Lazy initialization on first user interaction
let audioCtx = null;
function getAudioCtx() {
if (!audioCtx && typeof AudioContext !== 'undefined') {
audioCtx = new (window.AudioContext || window.webkitAudioContext)();
}
if (audioCtx && audioCtx.state === 'suspended') {
audioCtx.resume().catch(() => {});
}
return audioCtx;
}
Volume Control
// Read from CSS custom property (set by settings page)
function getMasterVolume() {
const vol = parseFloat(getComputedStyle(document.documentElement)
.getPropertyValue('--slop-sound-volume'));
return isNaN(vol) ? 0.1 : vol;
}
Respecting Reduced Motion
// Check global settings and prefers-reduced-motion
function isSoundEnabled() {
return getSoundOn() && !document.body.classList.contains('slop-sound-disabled');
}
// In play function:
if (slop.reduceMotion) return false; // respect reduced motion
Event System Integration
// Toast sounds
slop.on('toast', () => playUISound('toast'));
// Passport stamp earned
slop.on('stamp', () => playUISound('success'));
// Modal open/close
slop.on('modal-open', () => playUISound('modal-open'));
slop.on('modal-close', () => playUISound('modal-close'));
// Copy events
document.addEventListener('copy', (e) => {
if (e.isTrusted) playUISound('copy');
});
โฟ Accessibility
- Opt-in by default โ Sounds are off until explicitly enabled
- Reduced motion support โ Automatically disabled when user prefers reduced motion
- Keyboard accessible โ All interactive sounds trigger on keyboard activation (Enter/Space)
- No autoplay โ Sounds only play on explicit user interaction
- Volume control โ Global volume slider (0-100%) in Settings
- Debounced hover sounds โ 100ms debounce prevents rapid-fire hover sounds
- ARIA labels โ All sound controls have proper labels
- WCAG compliant โ 44px minimum touch targets, sufficient contrast
Testing Accessibility
- Enable Reduce Motion in System Preferences โ Accessibility โ Display
- Reload the page โ sounds should be automatically disabled
- Enable sounds in Settings โ verify they work
- Set volume to 0% โ verify no sounds play
- Navigate with keyboard โ verify click sounds on Enter/Space
๐จ Customization
Disable Specific Sounds
Add data-no-hover-sound, data-no-click-sound, data-no-toggle-sound, or data-no-select-sound to any element to opt it out:
Programmatic Control
// Play a specific sound manually
window.slopUISoundsUI.play('success', 0.5);
// Check current state
console.log(window.slopUISoundsUI.getMasterVolume()); // 0.1
console.log(window.slopUISoundsUI.isSoundEnabled()); // true/false
// Get AudioContext for advanced use
const ctx = window.slopUISoundsUI.getAudioCtx();
Adding Custom Sounds
Edit site/js/ui-sounds-rules.js and add to UI_SOUNDS array:
{
id: 'custom-sound',
label: '๐ต Custom Sound',
desc: 'A custom sound for my feature',
category: 'ui',
play(ctx, volume = 1) {
const osc = ctx.createOscillator();
const gain = ctx.createGain();
osc.type = 'sine';
osc.frequency.value = 440;
gain.gain.value = volume * 0.3;
osc.connect(gain).connect(ctx.destination);
osc.start();
osc.stop(ctx.currentTime + 0.2);
}
}