Created
December 21, 2019 03:36
-
-
Save aiba/bbc7563255ffd62236fead9c67fe4699 to your computer and use it in GitHub Desktop.
Plays gong sound at random interval, repeatedly.
This file contains hidden or 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
#!/usr/bin/env clojure | |
(require '[clojure.java.io :as io]) | |
(import 'javax.sound.sampled.AudioSystem) | |
(defn url->bytes [^String url] | |
(with-open [xin (io/input-stream (java.net.URL. url)) | |
xout (java.io.ByteArrayOutputStream.)] | |
(io/copy xin xout) | |
(.toByteArray xout))) | |
(def gong-bytes (url->bytes "http://soundbible.com/grab.php?id=2062&type=wav")) | |
(defn gong! [] | |
(let [s (-> gong-bytes io/input-stream AudioSystem/getAudioInputStream)] | |
(future | |
(println (java.util.Date.) "GONG") | |
(doto (AudioSystem/getClip) (.open s) (.start))))) | |
(defn sleep-rand-mins [a b] | |
(let [n (+ a (* (rand) (- b a)))] | |
(println "sleeping for" n "minutes") | |
(Thread/sleep (int (* 1000 60 n))))) | |
(loop [] | |
(gong!) | |
(sleep-rand-mins 2 13) | |
(recur)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment