Skip to content

Instantly share code, notes, and snippets.

@sudofox
Created January 3, 2023 20:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sudofox/fbe847eddb9af8f5e8d36c35163bef61 to your computer and use it in GitHub Desktop.
Save sudofox/fbe847eddb9af8f5e8d36c35163bef61 to your computer and use it in GitHub Desktop.
US/NANP Precise Tone Plan compliant dial tone generator (html)
<!DOCTYPE html>
<html>
<head>
<title>Dial Tone Generator</title>
</head>
<body>
<button id="startButton">Start</button>
<button id="stopButton">Stop</button>
<script>
const startButton = document.getElementById("startButton");
const stopButton = document.getElementById("stopButton");
// Create an audio context
const audioCtx = new (window.AudioContext || window.webkitAudioContext)();
// Create an oscillator node for the dial tone
const dialOscillator = audioCtx.createOscillator();
dialOscillator.frequency.value = 350; // Dial tone frequency
dialOscillator.type = "sine";
dialOscillator.start(); // Start the oscillator
// Create another oscillator node for the second frequency
const dialOscillator2 = audioCtx.createOscillator();
dialOscillator2.frequency.value = 440; // Second frequency
dialOscillator2.type = "sine";
dialOscillator2.start(); // Start the oscillator
// Create a gain node to control the dial tone volume
const dialGain = audioCtx.createGain();
dialGain.gain.value = 0.5; // Dial tone volume
dialGain.connect(audioCtx.destination);
// Disconnect the oscillators when the stop button is clicked
stopButton.addEventListener("click", () => {
dialOscillator.disconnect();
dialOscillator2.disconnect();
});
// Connect the oscillators when the start button is clicked
startButton.addEventListener("click", () => {
dialOscillator.connect(dialGain);
dialOscillator2.connect(dialGain);
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment