user
In JavaScript, develop an interactive web page that uses the Web Audio API to generate different tones based on user input. Make sure to include controls for pitch and volume. PLAINFORMAT
assistant
<!DOCTYPE html>
<html>
<head>
    <title>Interactive Tone Generator</title>
</head>
<body>
    <div>
        <label for="pitch">Pitch:</label>
        <input type="range" id="pitch" min="20" max="2000" value="440">
    </div>
    <div>
        <label for="volume">Volume:</label>
        <input type="range" id="volume" min="0" max="1" step="0.01" value="0.5">
    </div>
    <button id="start">Start</button>
    <button id="stop">Stop</button>

    <script>
        var context = new (window.AudioContext || window.webkitAudioContext)();
        var oscillator = context.createOscillator();
        var gainNode = context.createGain();

        oscillator.connect(gainNode);
        gainNode.connect(context.destination);

        document.getElementById('start').addEventListener('click', function() {
            oscillator.start(0);
        });

        document.getElementById('stop').addEventListener('click', function() {
            oscillator.stop(0);
        });

        document.getElementById('pitch').addEventListener('input', function() {
            oscillator.frequency.value = this.value;
        });

        document.getElementById('volume').addEventListener('input', function() {
            gainNode.gain.value = this.value;
        });
    </script>
</body>
</html>