JSFiddle - React, Tailwind, and code Playground
HTML
<input type="button" value="play" id="play">
<input type="button" value="stop" id="stop">
JavaScript
var context = new (window.AudioContext || window.webkitAudioContext)();
var osc = context.createOscillator();
var gain = context.createGain();
var now = context.currentTime;
osc.frequency.value = 100;
osc.type = "sine";
osc.connect(gain);
osc.start(0);
gain.connect(context.destination);
gain.gain.value = 0;
var trigger = document.getElementById('play');
var stop = document.getElementById('stop');
trigger.addEventListener('click', function(){
gain.gain.setValueAtTime(gain.gain.value, now);
gain.gain.linearRampToValueAtTime( 1.0, now + 2.0 );
gain.gain.linearRampToValueAtTime ( 0.0, now + 4.0 );
});
//osc.stop(0);