
index.html, script.js, and style.css.Open script.js and add the following example to play a simple sound:
const synth = new Tone.Synth().toDestination();
document.getElementById("playButton").addEventListener("click", () => {
synth.triggerAttackRelease("C4", "8n");
});
Update index.html to add a button element.
<button id="playButton">Play Sound</button>
Optional Tone.Loop
const loop = new Tone.Loop((time) => {
synth.triggerAttackRelease("E4", "8n", time);
}, "4n").start(0);
Tone.Transport.start();
Reverb
const reverb = new Tone.Reverb(0.5).toDestination();
synth.connect(reverb);