From 0a937461f184a3db811a274afd84eb1182657ffd Mon Sep 17 00:00:00 2001 From: Kenneth Date: Sun, 21 Jul 2024 19:06:07 +0100 Subject: [PATCH] feat: add button click effect --- server.py | 4 ++-- web/script.js | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/server.py b/server.py index d73ea07..61db4d1 100644 --- a/server.py +++ b/server.py @@ -23,7 +23,7 @@ prompts = [ ] -model = modal.Cls.lookup("infinifi", "Model") +# model = modal.Cls.lookup("infinifi", "Model") @asynccontextmanager @@ -75,7 +75,7 @@ def advance(): else: current_index = current_index + 1 - threading.Thread(target=generate_new_audio).start() + # threading.Thread(target=generate_new_audio).start() t = threading.Timer(60, advance) t.start() diff --git a/web/script.js b/web/script.js index f1d761d..a1a4740 100644 --- a/web/script.js +++ b/web/script.js @@ -1,5 +1,7 @@ const playBtn = document.getElementById("play-btn"); const catImg = document.getElementsByClassName("cat")[0]; +const clickAudio = new Audio("/audio/click.wav"); +const clickReleaseAudio = new Audio("/audio/click-release.wav"); const CROSSFADE_DURATION_MS = 5000; const CROSSFADE_INTERVAL_MS = 20; @@ -81,6 +83,17 @@ function animateCat() { }, 500); } +playBtn.onmousedown = () => { + clickAudio.play(); + document.addEventListener( + "mouseup", + () => { + clickReleaseAudio.play(); + }, + { once: true }, + ); +}; + playBtn.onclick = () => { if (isPlaying) { pauseAudio();