-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
let context = new (window.AudioContext || window.webkitAudioContext)(); | ||
let intervalId; | ||
let isBeeping = false; | ||
|
||
function playBeep() { | ||
let oscillator = context.createOscillator(); | ||
oscillator.type = 'sine'; // You can change the type (sine, square, triangle, etc.) | ||
oscillator.frequency.setValueAtTime(440, context.currentTime); // Frequency in Hertz (440Hz is an A4 note) | ||
|
||
let gainNode = context.createGain(); | ||
gainNode.gain.setValueAtTime(0.1, context.currentTime); // Volume control | ||
|
||
oscillator.connect(gainNode); | ||
gainNode.connect(context.destination); | ||
|
||
oscillator.start(); | ||
oscillator.stop(context.currentTime + 0.1); // Play beep for 100ms | ||
} | ||
|
||
function toggleBeeping() { | ||
if (!isBeeping) { | ||
intervalId = setInterval(playBeep, 1000); | ||
document.getElementById("toggleBeep").innerText = "Stop Beeping"; | ||
isBeeping = true; | ||
} else { | ||
clearInterval(intervalId); | ||
document.getElementById("toggleBeep").innerText = "Start Beeping"; | ||
isBeeping = false; | ||
} | ||
} | ||
|
||
document.getElementById("toggleBeep").addEventListener("click", toggleBeeping); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Beep Generator</title> | ||
<style> | ||
body { | ||
font-family: Arial, sans-serif; | ||
text-align: center; | ||
margin-top: 50px; | ||
} | ||
button { | ||
padding: 10px 20px; | ||
font-size: 16px; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<h1>Beep Sound Generator</h1> | ||
<button id="toggleBeep">Start Beeping</button> | ||
|
||
<script src="app.js"></script> | ||
</body> | ||
</html> |