Tone.js

15.1.22 · active · verified Sun Apr 19

Tone.js is a comprehensive Web Audio framework designed for creating interactive music directly within the browser. It provides high-level abstractions over the Web Audio API, offering a wide array of instruments (like Synths, Samplers), effects (Reverb, Delay), and advanced signal processing tools for dynamic audio manipulation. Currently stable at version 15.1.22, the library has seen consistent development, including a significant transition to TypeScript in its 14.7.x series, enhancing type safety and developer experience. Its release cadence is moderate, with major updates introducing new features and improvements, while also addressing breaking changes through version increments. Key differentiators include its robust scheduling system (`Tone.Transport`), extensive collection of DSP modules, and focus on real-time interactive performance, making it a popular choice for web-based musical applications and installations.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart initializes Tone.js, creates a basic synthesizer, and schedules a short melody to play upon user interaction, demonstrating fundamental setup and event scheduling.

import { Synth, Destination, start, now, Transport } from 'tone';

const playButton = document.createElement('button');
playButton.textContent = 'Play Synth';
document.body.appendChild(playButton);

playButton.addEventListener('click', async () => {
  // Start the Tone.js audio context on user interaction
  await start();
  console.log('Audio context started.');

  // Create a simple synthesizer
  const synth = new Synth().toDestination();

  // Schedule some notes
  const synthNotes = [
    { note: 'C4', time: 0, duration: '8n' },
    { note: 'E4', time: '8n', duration: '8n' },
    { note: 'G4', time: '4n', duration: '8n' },
    { note: 'C5', time: '2n', duration: '8n' }
  ];

  Transport.scheduleOnce(() => {
    synthNotes.forEach(event => {
      synth.triggerAttackRelease(event.note, event.duration, now() + Transport.seconds + event.time);
    });
  }, 0); // Schedule immediately when transport starts

  // Start the transport to play scheduled events
  Transport.start();

  console.log('Synth playing...');
});

view raw JSON →