[WIP] Add ability to play sound

Signed-off-by: Danila Fedorin <danila.fedorin@gmail.com>
This commit is contained in:
2025-12-06 17:42:59 -08:00
parent 1e5ed34f0f
commit 9660c0d665
2 changed files with 74 additions and 5 deletions

View File

@@ -0,0 +1,15 @@
window.addEventListener("load", (event) => {
for (const elt of document.getElementsByClassName("mt-sound-play-button")) {
elt.addEventListener("click", (event) => {
const audioCtx = new (window.AudioContext || window.webkitAudioContext)();
for (const freq of event.target.getAttribute("data-sound-info").split(",")) {
const oscillator = audioCtx.createOscillator();
oscillator.type = "sine"; // waveform: sine, square, sawtooth, triangle
oscillator.frequency.value = parseInt(freq); // Hz
oscillator.connect(audioCtx.destination);
oscillator.start();
oscillator.stop(audioCtx.currentTime + 2); // stop after 1 second
}
});
}
});