    oscillator.frequency.value = frequency;

      // Connect the oscillator to the destination (speakers)
      oscillator.connect(audioCtx.destination);

      // Start the oscillator
      oscillator.start();

      // Stop the oscillator after the specified duration
      oscillator.stop(audioCtx.currentTime + duration);

      // Clean up the audio context after the sound has played
      oscillator.onended = function() {
        audioCtx.close();
      };
    }
  </script>
</body>
</html>
