With the spread of smart speakers and wireless earphones, the importance of sound in interaction design is increasing day by day. However, compared to many researches and practices in the fields of visual design and animation in interaction design, it see
npm install snd-libInteraction should not be limited to text and visuals, but should be richer than that. In order to make the intensity of interaction richer and stronger, we should have more discussion about sound.
However, in the area of interaction design, there are fewer sound designers than visual designers and programmers, and there are certainly barriers to creating sound.
To encourage UX developers to further explore discussions in the area of interaction design with sound, we have developed UI sound assets that can be used for free without worrying about licensing.
UI sound assets, developed in collaboration with multiple sound designers, are designed to fit the components used in many modern UIs. Each asset is individually designed with a different concept, so you can feel the change in texture and tone by switching the sounds.
We hope that you will use it as a resource to further refine the quality of UX for your apps, services, and products under development, and that it will help you to explore the field of sound design.
All UI sounds published on "SND" can be used for free, regardless of whether they are commercial or non-commercial. Therefore, you can use them not only for prototyping, but also for implementation in your services. *Please check the terms of use for details.
- snd.dev
- Demo for JavaScript Developer
- Demo for HTML/CSS Developer
sh
$ npm install snd-lib
`#### CDN
`html
`Usage
node
`javascript
import Snd from 'snd-lib';const snd = new Snd();
// Get all anchor elements.
const links = document.getElementsByTagName('a');
// Event handler for click
const onClick = (e) => {
snd.play(Snd.SOUNDS.TAP);
}
// Load audio file
snd.load(Snd.KITS.SND01).then(() => {
// Listen click event of all anchor elements.
for (let i=0; i links[i].addEventListener('click', onClick)
}
})
`HTML
`html
Link
`API
$3
#### note
- You need to initialize Web Audio API from pointer event at first.
- This library adds a click event listener to window to initialize Audio Context.
- By setting the preloadSoundKit option to null when create an instance and call the load method manually, you can wait for the sound kit to load
$3
`javascript
new Snd(options: SndOptions);
`
#### SndOptions
| name | type | default | description |
| ---------------- | ------- | ------- | ------------------------------------- |
| easySetup | boolean | true | If this option is set to true, Snd will automatically add event listeners to the HTML Elements with "snd__[sound key]" classes. |
| muteOnWindowBlur | boolean | true | If this option is set to true, Snd will fade out the audio volume when browser or browser's tab becomes inactive. |
| preloadSoundKit | null \| string | null | Sound Kit key to pre load. |
#### PlayOptions
| name | type| default | description |
| ---------------- | --------------------- | ------- | ------------------------------------- |
| index | null \| number | null | Sound playback number |
| loop | boolean | false | whether loop or not |
| volume | number | 1 | Audio volume |
| delay | number | 0 | Delay time (second) |
| duration | number | -1 | Playing duration (second). If this is set to -1 the playing duration will be the original sound duration. |
| callback | (id: number) => void | () => {} | Callback function that will be called when the sound completes playing. |
$3
#### CHANGE_SOUND_KIT: string static readonly
Event name which will be triggered when a sound kit has changed
#### SOUNDS: {[key: string]: string} static readonly
An object that contains all keys of the sound types. (ex: "Button", "Tap")
#### KITS: {[key: string]: string} static readonly
An object that contains all keys of sound kits.
#### masterVolume: number static
master volume
$3
#### load(kitKey: string): Promise
Load sound kit
|arg|type|description|
|-|-|-|
|kitKey|string | Key of the sound kit. You can pass the value using Snd.KITS object. |
#### play(soundKey: string, options?: PlayOptions): void
Play sound
|arg|type|description|
|-|-|-|
|soundKey|string | Key of the sound. You can pass the value using Snd.SOUNDS object. |
|options|PlayOptions| |
#### playTap(options?: PlayOptions): void
Play Tap sound
#### playSwipe(options?: PlayOptions): void
Play Swipe sound
#### playType(options?: PlayOptions): void
Play Type sound
#### playButton(options?: PlayOptions): void
Play Button sound
#### playCaution(options?: PlayOptions): void
Play Caution sound
#### playCelebration(options?: PlayOptions): void
Play Celebration sound
#### playDisabled(options?: PlayOptions): void
Play Disabled sound
#### playNotification(options?: PlayOptions): void
Play Notification sound
#### playProgressLoop(options?: PlayOptions): void
Play ProgressLoop sound
#### playRingtoneLoop(options?: PlayOptions): void
Play RingtoneLoop sound
#### playSelect(options?: PlayOptions): void
Play Select sound
#### playTransitionUp(options?: PlayOptions): void
Play TransitionUp sound
#### playTransitionDown(options?: PlayOptions): void
Play TransitionDown sound
#### playToggleOn(options?: PlayOptions): void
Play ToggleOn sound
#### playToggleOff(options?: PlayOptions): void
Play ToggleOff sound
#### stop(soundKey: string): void
Stop all sounds with a specific sound key.
|arg|type|description|
|-|-|-|
|soundKey|string | Key of sound. You can pass the value using Snd.SOUNDS object. |
#### mute(): void
Mute
#### unmute(): void
Unmute
$3
#### kit: string
Currently selected sound kit key.
#### isMuted: boolean
Muted or not.
#### isWindowBlurred: boolean
Browser window is blurred or not.
$3
#### CHANGE_SOUND_KIT
Triggered when the sound kit has change.
$3
#### Sound Kit
| name | key | author |
| ---------------- | --- |----------------- |
| SND01 "sine" | 01 | Yasuhiro Tsuchiya |
| SND02 "piano" | 02 | Ayako Taniguchi |
| SND03 "industrial" | 03 | INDUSTRIAL JP |
#### key
`javascript
import Snd from "snd-lib";
Snd.SOUNDS
``#### HTML Class names for easy setup.
- If the easySetup option is set to true, Snd will automatically play sound for HTML Elements with classes below.
| name | compatible elements | event |
| ---------- | -------- | ---------- |
| snd__button| any | click |
| snd__caution | any | click |
| snd__celebration | any | click |
| snd__disabled | any | click |
| snd__notification| any | click |
| snd__select| select, input(type="radio") | change |
| snd__tap | any | mousedown, touchstart |
| snd__toggle| input(type="checkbox") | change |
| snd__transition_down | any | click |
| snd__transition_up | any | click |
| snd__type| textarea, input(type="text,email,number,password,search,tel,url") | keydown |