JSFiddle - React, Tailwind, and code Playground
by nynexman4464
HTML
<button onclick="doit()">
doit
</button>
JavaScript
function doit(){
// Create an audio context
var audioCtx = new AudioContext();
// Create an oscillator for the carrier tone (2000 Hz)
var carrierOsc = audioCtx.createOscillator();
carrierOsc.type = "sine";
carrierOsc.frequency.value = 2000;
// Create an oscillator for the modulation tone (12 Hz)
var modOsc = audioCtx.createOscillator();
modOsc.type = "square";
modOsc.frequency.value = 12;
// Create a gain node to control the volume of the tone
var gainNode = audioCtx.createGain();
gainNode.gain.value = 0.5; // adjust the volume as needed
// Connect the oscillators and gain node together
carrierOsc.connect(gainNode);
modOsc.connect(carrierOsc.frequency);
// Start the oscillators
carrierOsc.start();
modOsc.start();
// Connect the output of the gain node to the audio context's destination
gainNode.connect(audioCtx.destination);
}