-
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
1 parent
d182842
commit 65633d1
Showing
1 changed file
with
34 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,34 @@ | ||
javascript:(function() { | ||
// Create an AudioContext | ||
const audioContext = new (window.AudioContext || window.webkitAudioContext)(); | ||
|
||
// Function to generate a random tone | ||
function generateRandomTone() { | ||
const duration = 1; // in seconds | ||
const frequency = Math.random() * 2000 + 200; // random frequency between 200 and 2200 Hz | ||
|
||
// Create an OscillatorNode | ||
const oscillator = audioContext.createOscillator(); | ||
oscillator.type = 'sine'; // you can experiment with other oscillator types like 'sawtooth', 'square', or 'triangle' | ||
oscillator.frequency.value = frequency; | ||
|
||
// Create a GainNode for controlling the volume | ||
const gainNode = audioContext.createGain(); | ||
gainNode.gain.value = 0.5; // adjust the volume here | ||
|
||
// Connect the nodes | ||
oscillator.connect(gainNode); | ||
gainNode.connect(audioContext.destination); | ||
|
||
// Start the oscillator | ||
oscillator.start(); | ||
|
||
// Stop the oscillator after the specified duration | ||
setTimeout(() => { | ||
oscillator.stop(); | ||
}, duration * 1000); | ||
} | ||
|
||
// Generate a random tone | ||
generateRandomTone(); | ||
})(); |