🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

clicktone

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

clicktone

ClickTone is a lightweight helper for UI sound feedback. It wraps the Web Audio API, giving you instant click‑sounds with volume control, throttling, callbacks, and an iOS resume workaround.

1.8.0
latest
Source
npm
Version published
Weekly downloads
4
-50%
Maintainers
1
Weekly downloads
 
Created
Source

clicktone

npm GitHub package version NPM Downloads

ClickTone is a lightweight helper for UI sound feedback. It wraps the Web Audio API, giving you instant click‑sounds with volume control, throttling, callbacks, and an iOS resume workaround.

1.2kB gzipped

Demo


Install

yarn add clicktone

Import

import ClickTone from 'clicktone';

Usage

<audio preload="auto">
  <source id="click-source" src="./click.mp3" type="audio/mpeg" />
  <source src="./click.ogg" type="audio/ogg" />
</audio>
const sound = new ClickTone({
  // Any of the forms work:
  // file: './sound.mp3',
  // file: new URL('./sound.mp3', import.meta.url).href,
  // file: document.querySelector('#click-source') as HTMLSourceElement,
  file: { id: 'click-source' },

  volume: 0.7,
  throttle: 100,
  callback: () => console.log('done'),
  debug: true,
});

button.addEventListener('click', () => click.play());

ClickTone uses the Web Audio API, which supports many audio file formats: MP3, WAV, OGG, AAC and others. Note that not all browsers support these formats.
Tip: you can also override the source at call‑time: click.play('./alt.wav').

Options

OptionTypeDefaultDescription
filestring | HTMLSourceElement | { id: string }Audio source. Either a direct URL, an actual <source> element, or an object whose id maps to a <source> already in the DOM.
volumenumber1Playback volume 01.
callback((error?: Error) => void) | nullnullCalled after playback ends or if an error occurs.
throttlenumber0Debounce interval in ms. Playback requests arriving sooner are ignored.
debugbooleanfalseLog internal errors/warnings to the console.

License

clicktone is released under MIT license.

Keywords

MP3

FAQs

Package last updated on 17 Apr 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts