JSFiddle - React, Tailwind, and code Playground
HTML
<button id="start">start</button>
<button id="stop">stop</button>
JavaScript
var ctx = new AudioContext();
var osc = ctx.createOscillator();
osc.frequency.value = 200;
var g = ctx.createGain();
g.gain.value = 0;
osc.start(ctx.currentTime);
osc.connect(g);
g.connect(ctx.destination);
function startOsc(bool) {
if(bool === undefined) bool = true;
if(bool === true) {
g.gain.value = 1;
} else {
g.gain.value = 0;
}
}
$(document).ready(function() {
$("#start").click(function() {
startOsc();
});
$("#stop").click(function() {
startOsc(false);
});
});