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

@spa-audio/core

v1.1.3

Published

Core JavaScript library for parsing and rendering SPA (Synthetic Parametric Audio) - procedural sound effects for the web

Readme

spa-audio

Core JavaScript library for parsing and rendering SPA (Synthetic Parametric Audio) files.

Features

  • Tiny: < 20KB gzipped
  • Fast: Renders sounds in < 10ms
  • Zero Dependencies: Uses native Web Audio API
  • TypeScript Support: Full type definitions included
  • Universal: Works in browsers and Node.js

Installation

npm install spa-audio

Quick Start

import { renderSPA, playSPA } from 'spa-audio';

// Play a simple click sound
await playSPA(`
  <spa xmlns="https://spa.audio/ns" version="1.0">
    <tone wave="sine" freq="800" dur="0.05"
          envelope="0,0.02,0,0.03"/>
  </spa>
`);

// Render to AudioBuffer for reuse
const buffer = await renderSPA(`
  <spa xmlns="https://spa.audio/ns" version="1.0">
    <tone wave="sine" freq="440" dur="1.0"/>
  </spa>
`);

// Play the buffer multiple times
const ctx = new AudioContext();
const source = ctx.createBufferSource();
source.buffer = buffer;
source.connect(ctx.destination);
source.start();

API Reference

renderSPA(xml, options?)

Renders SPA XML to an AudioBuffer.

const buffer = await renderSPA(spaXML, {
  sampleRate: 48000,  // default: 48000
  channels: 2         // default: 2 (stereo)
});

playSPA(xml, options?)

Plays SPA XML directly through the default audio output.

await playSPA(spaXML);

parseSPA(xml)

Parses SPA XML into a JavaScript object (AST).

const ast = parseSPA(spaXML);
console.log(ast);
// { version: '1.0', sounds: [...] }

validate(xml)

Validates SPA XML against the schema.

const errors = validate(spaXML);
if (errors.length === 0) {
  console.log('Valid SPA!');
} else {
  console.error('Validation errors:', errors);
}

Dynamic Sound Generation

Generate sounds parametrically:

function createNotification(frequency, duration) {
  return `
    <spa xmlns="https://spa.audio/ns" version="1.0">
      <tone wave="sine" freq="${frequency}" dur="${duration}"
            envelope="0,0.05,0.6,0.15"/>
    </spa>
  `;
}

// Higher pitch for success
await playSPA(createNotification(880, 0.2));

// Lower pitch for error
await playSPA(createNotification(400, 0.3));

Layering Sounds

Create complex effects with groups:

const laserSound = `
  <spa xmlns="https://spa.audio/ns" version="1.0">
    <group>
      <tone wave="saw" dur="0.3"
            freq.start="1000" freq.end="200" freq.curve="exp"
            envelope="0,0.1,0,0.2"/>
      <noise color="white" dur="0.1" amp="0.3"
             envelope="0,0.05,0,0.05"/>
    </group>
  </spa>
`;

await playSPA(laserSound);

Browser Support

  • Chrome/Edge 66+
  • Firefox 61+
  • Safari 14.1+
  • Opera 53+

Requires Web Audio API support.

Node.js Usage

For server-side rendering or testing:

// Node.js environment will use a Web Audio API polyfill
const { renderSPA } = require('spa-audio');

const buffer = await renderSPA(spaXML);
// Returns a Float32Array in Node.js

Performance

Typical render times:

  • Simple tone: < 1ms
  • Complex layered sound: < 10ms
  • 10 layered tones: < 15ms

Examples

See the spa-spec repository for a complete library of example sounds.

Related Projects

License

MIT