Browser synthesizer stack (Tone.js) and LLM-generated music as JSON
tone.jssvelteweb-audiochiptunellmmusic-generation
Research done in March 2026 for "synth", a browser music tool for non-musicians making fast video game music (chiptune, boss-battle tracks) with AI help. Eight research passes compared audio libraries, UI frameworks, and ways to get an LLM to compose. The conclusions are reusable for any browser audio app.
Library choice
- Tone.js is the clear choice for a browser synth: built-in synths, a BPM-aware transport and sequencer, an effects chain, and recording, about 150 KB. Howler.js and Pizzicato.js are playback/effects libraries, not synthesis engines.
- Svelte 5 (with Vite) suits real-time audio UIs: it compiles to plain JavaScript with no virtual DOM, so UI updates cost little on the main thread. A full app targets roughly 160 to 180 KB gzipped and can be deployed as static files.
Sounds without samples
- Kick:
Tone.MembraneSynth. Hi-hat:Tone.MetalSynth. Snare:Tone.NoiseSynth. A whole drum kit needs no sample files. - Chiptune leads:
Tone.FMSynth(or square-wave synths); chords:Tone.PolySynth. Tone.BitCrusheris the key effect for a retro 8-bit sound; also available: Reverb, Delay, Distortion, Chorus, Phaser, Compressor.- Export:
Tone.RecorderwrapsMediaRecorder. Note it produces a compressed container (usually WebM/Opus); real WAV needs an offline render to a buffer and a WAV encoder.
Keyboard mapping convention
The common computer-keyboard piano layout: home row = white keys, row above = black keys (A = C4, W = C#4, S = D4, E = D#4, D = E4, F = F4, T = F#4, and so on).
Getting an LLM to compose
- Have the model emit structured JSON (tempo, key, tracks, each with instrument, notes with time and duration, effects), not MIDI or prose. JSON maps directly onto Tone.js parts and is easy to validate.
- Enforce the schema in the instructions (a project
CLAUDE.mdplus skills such as/compose,/modify-track,/drumsthat all output the same schema). - For iterative edits, decide between multi-turn context and resending the current song JSON each time; resending state is more robust.
- Hosted music-generation APIs (Suno, MusicGen, Magenta.js) produce audio or MIDI that is hard to edit afterward; symbolic JSON keeps every note editable.
- With a Claude subscription rather than API credits, route generation through a local
service that wraps the Claude CLI (claude-service (ProcrastinAI's webhook runner for headless Claude)): the app POSTs a prompt, the CLI
runs with the app's directory as cwd so its
CLAUDE.mdand skills apply, and the result comes back by callback or polling.
See also
- Procedural music and sound effects with the Web Audio API
- claude-service (ProcrastinAI's webhook runner for headless Claude)