Learn how to create and play procedural audio with SPA in just a few steps
Choose your platform and install the SPA packages. All packages are lightweight and have zero dependencies.
npm install @spa-audio/react
Components:
import { SPAButton, SPAPlayer } from '@spa-audio/react';
// Button with sound
<SPAButton src="/sounds/click.spa">
Click Me
</SPAButton>
// Inline SPA
<SPAButton spa='<spa><tone wave="sine" freq="800" dur="0.05"/></spa>'>
Play
</SPAButton>
// Full player
<SPAPlayer src="/sounds/music.spa" />Hook for custom usage:
import { useSPA } from '@spa-audio/react';
const { play, stop, loading } = useSPA('/sound.spa');
// Trigger playback
<button onClick={play}>Play</button>SPA was designed to be AI-friendly. LLMs can easily generate valid SPA files because the format is declarative XML with clear parameters.
This comprehensive prompt includes:
Understand how to construct SPA files from basic building blocks. Every sound starts with these fundamentals.
Every SPA file follows this structure:
<?xml version="1.0" encoding="UTF-8"?> <spa xmlns="https://spa.audio/ns" version="1.0"> <!-- Your sound elements go here --> <tone wave="sine" freq="440" dur="1" /> </spa>
<tone> - Oscillator soundsCreate pure tones with different waveforms
<tone wave="sine" freq="440" dur="1" amp="0.5" />
<noise> - Noise generatorsGenerate different colors of noise
<noise color="white" dur="0.5" amp="0.3" />
<group> - Layer soundsPlay multiple sounds simultaneously
<group> <tone wave="sine" freq="261.63" dur="1" /> <!-- C --> <tone wave="sine" freq="329.63" dur="1" /> <!-- E --> <tone wave="sine" freq="392" dur="1" /> <!-- G --> </group>
<sequence> - Time eventsPlay sounds in sequence with timing
<sequence> <tone wave="sine" freq="261.63" dur="0.25" at="0" /> <tone wave="sine" freq="329.63" dur="0.25" at="0.25" /> <tone wave="sine" freq="392" dur="0.25" at="0.5" /> </sequence>
Complete reference for all elements, attributes, and advanced features
Try SPA in your browser with instant playback and examples