JSFiddle - React, Tailwind, and code Playground
Babel + JSX
let audioCtx = new AudioContext();
// Create nodes
let osc = audioCtx.createOscillator();
let gain = audioCtx.createGain();
// Set parameters
osc.frequency.value = 440;
gain.gain.value = 1;
// Schedule parameter changes
// A ramp from 1 to 0.5 between times 0.97 and 1
gain.gain.setValueAtTime(1, 1 - 0.03);
gain.gain.linearRampToValueAtTime(0.5, 1);
// Connect graph
osc.connect(gain);
gain.connect(audioCtx.destination);
// Schedule start and stop
osc.start();
osc.stop(audioCtx.currentTime + 2);