Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
jianwu committed Oct 22, 2024
1 parent 89a2033 commit 7e5f712
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
32 changes: 32 additions & 0 deletions beep/app.js
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);
25 changes: 25 additions & 0 deletions beep/index.html
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>

0 comments on commit 7e5f712

Please sign in to comment.