Skip to content

sethbrasile/ez-web-audio

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

945 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

npm version CI License: MIT

EZ Web Audio

A TypeScript library that makes the Web Audio API easy to use. No dependencies.

EZ Web Audio wraps the Web Audio API with a simpler, more intuitive interface. It covers sound playback, music tracks with pause/seek/position tracking, synthesizers with filters and ADSR envelopes, drum machines, samplers, audio sprites, effects chains, and soundfont support. Originally Ember Audio, it has been rewritten as a framework-agnostic TypeScript library that works with any frontend stack.

Installation

npm install ez-web-audio

Quick Start

Play a Sound

import { createSound } from 'ez-web-audio'

const click = await createSound('click.mp3')
click.play()

// Sounds can overlap — each play creates a new source
click.play()
click.play()

Music Track with Controls

import { createTrack } from 'ez-web-audio'

const song = await createTrack('song.mp3')
song.play()

// Pause and resume
song.pause()
song.resume()

// Seek to 30 seconds
song.seek(30).as('seconds')

// Read current position
console.log(song.position.string) // '0:30'

Synthesizer

import { createOscillator } from 'ez-web-audio'

const synth = await createOscillator({
  frequency: 440,
  type: 'sine',
  envelope: { attack: 0.01, decay: 0.3, sustain: 0.4, release: 0.5 },
})

synth.play()
setTimeout(() => synth.stop(), 1000)

Features

  • Sound playback (one-shot sounds with overlap support)
  • Music tracks (pause, resume, seek, position tracking)
  • Synthesizer (oscillators with sine/square/sawtooth/triangle waves)
  • ADSR envelopes (attack, decay, sustain, release)
  • Effects chain (filters, gain effects, custom effects with bypass)
  • Drum machine (BeatTrack with rhythmic patterns)
  • Sampler (round-robin playback for natural variation)
  • Audio sprites (named segments from a single audio file)
  • Soundfont support (load and play instrument samples)
  • Batch loading with progress tracking
  • Synchronized playback (playTogether)
  • Crossfade utility
  • Zero dependencies
  • Full TypeScript support with detailed type exports

ESM Only

This package is ESM-only. It requires Node.js 18+ or a modern bundler (Vite, Webpack 5+, Rollup, esbuild). If using TypeScript, set "moduleResolution": "bundler" or "node16" in your tsconfig.json.

Documentation

Full documentation is available at https://sethbrasile.github.io/ez-web-audio

The docs site includes:

  • Getting started guide
  • Core concepts and architecture overview
  • Full API reference with type signatures
  • Interactive examples and demos

License

MIT

About

Making the web audio API super EZ since 2024

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors