npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

uispeaker

v0.1.0

Published

Add interactive sounds to UI elements via data attributes

Downloads

7

Readme

uispeaker

Add interactive sounds to any HTML element with a single data attribute. No framework required.

Install

npm install uispeaker

Quick Start

Script Tag (auto-initializes)

<script src="https://unpkg.com/uispeaker/dist/uispeaker.global.js"></script>

<button data-uispeaker="click">Click me</button>
<input data-uispeaker="keystroke" placeholder="Type here..." />

That's it. The library scans the DOM, detects elements with data-uispeaker, and binds the appropriate sound automatically.

ES Module

import { UISpeaker } from 'uispeaker';

const speaker = new UISpeaker();
speaker.init();

Or use the convenience init function:

import { init } from 'uispeaker';

const speaker = init({ volume: 0.8 });

Data Attributes

| Attribute | Value | Description | |-----------|-------|-------------| | data-uispeaker | Sound name | The sound to play (e.g., click, tap, pop) | | data-uispeaker-event | Event type | Override auto-detected event (e.g., hover, input) | | data-uispeaker-close | Sound name | Sound to play on close (for toggle elements) |

Event Auto-Detection

The library infers the right event based on the element type:

| Element | Inferred Event | |---------|---------------| | <button>, <a>, ARIA roles | click | | <input type="text">, <textarea> | input (debounced) | | <input type="checkbox">, <select> | click | | <details>, <dialog> | open / close | | Elements with data-state | open / close |

Override with data-uispeaker-event:

<div data-uispeaker="hover" data-uispeaker-event="hover">Hover me</div>

Built-in Sounds

| Name | Category | Event | Description | |------|----------|-------|-------------| | click | click | click | Short digital click | | tap | click | click | Soft tap for toggles | | pop | click | click | Bubble pop for playful interactions | | keystroke | input | input | Single key press | | typewriter | input | input | Mechanical typewriter key | | hover | hover | hover | Subtle swoosh | | swoosh | hover | hover | Pronounced swoosh | | slide | mousemove | mousemove | Smooth slide | | open | toggle | open | Opening tone | | close | toggle | close | Closing tone | | success | notification | success | Positive chime | | error | notification | error | Alert tone | | warning | notification | warning | Cautionary beep |

Examples

Buttons

<button data-uispeaker="click">Save</button>
<button data-uispeaker="pop">Add to Cart</button>
<button data-uispeaker="tap">Toggle</button>

Text Input

<input data-uispeaker="keystroke" type="text" />
<textarea data-uispeaker="typewriter"></textarea>

Hover Effects

<div data-uispeaker="hover" data-uispeaker-event="hover">
  Hover for sound
</div>

Dropdowns and Dialogs

<details data-uispeaker="open" data-uispeaker-close="close">
  <summary>Open me</summary>
  <p>Content here</p>
</details>

Notifications (Programmatic)

import { UISpeaker } from 'uispeaker';

const speaker = new UISpeaker();
speaker.init();

// Play sounds programmatically
speaker.play('success');
speaker.play('error');
speaker.play('warning');

JavaScript API

Constructor

const speaker = new UISpeaker({
  cdnBase: 'https://your-cdn.com/sounds',  // Custom sound URL base
  volume: 0.8,                              // 0-1, default: 1
  muted: false,                             // Start muted, default: false
  root: document.body,                      // Root element to scan
  inputDebounce: 80,                        // Input debounce ms, default: 80
  mousemoveThrottle: 100,                   // Mousemove throttle ms, default: 100
});

Methods

| Method | Description | |--------|-------------| | init(root?) | Start scanning and observing the DOM | | play(name) | Play a sound by name | | volume(v) | Set master volume (0-1) | | getVolume() | Get current volume | | mute() | Mute all sounds | | unmute() | Unmute | | isMuted() | Check mute state | | register(name, entry) | Register a custom sound | | setCdnBase(url) | Change the CDN base URL | | sounds() | List all available sound names | | destroy() | Tear down and clean up |

Register Custom Sounds

speaker.register('custom-ding', {
  url: '/sounds/ding.mp3',
  defaultEvent: 'click',
  category: 'custom',
});
<button data-uispeaker="custom-ding">Custom Sound</button>

Script Tag API

When loaded via <script> tag, the library creates a window.UISpeaker global with the following methods:

<script src="https://unpkg.com/uispeaker/dist/uispeaker.global.js"></script>
<script>
  UISpeaker.volume(0.5);
  UISpeaker.mute();
  UISpeaker.unmute();
  UISpeaker.play('success');
  UISpeaker.register('ding', { url: '/sounds/ding.mp3' });
</script>

Browser Support

Works in all modern browsers that support the Web Audio API:

  • Chrome 35+
  • Firefox 25+
  • Safari 14.1+
  • Edge 79+

Note: Browsers require a user gesture (click, tap, keypress) before audio can play. UISpeaker handles this automatically -- sounds will begin playing after the user's first interaction with the page.

Bundle Size

| Format | Minified | Gzipped | |--------|----------|---------| | IIFE (script tag) | ~12 KB | ~4 KB | | ESM | ~11 KB | ~3.7 KB | | CJS | ~11 KB | ~3.7 KB |

Sounds are loaded on demand from CDN and are not included in the bundle.

License

MIT