keepme / src /hooks /useBeep.ts
narinder1231's picture
Add useBeep hook for audio beep functionality with start and stop controls
73a2501
raw
history blame contribute delete
486 Bytes
const beepSoundFile = new URL("../assets/beep.mp3", import.meta.url).href;
const beepSound = new Audio(beepSoundFile);
export function useBeep() {
let beepInterval: ReturnType<typeof setInterval> | null = null;
function startBeeping() {
beepSound.play();
beepInterval = setInterval(() => {
beepSound.play();
}, 3000);
}
function stopBeeping() {
if (beepInterval) {
clearInterval(beepInterval);
}
}
return { startBeeping, stopBeeping };
}