某生放送*1を聞きながら、自分でも書いてみたもの
めんどくせーー
(import 'javax.sound.sampled.AudioInputStream) (import 'javax.sound.sampled.AudioSystem) (import 'javax.sound.sampled.DataLine) (import 'javax.sound.sampled.DataLine$Info) (import 'javax.sound.sampled.SourceDataLine) (defn play [filepath] (let [file (java.io.File. filepath) in-stream (AudioSystem/getAudioInputStream file) format (.getFormat in-stream) info (DataLine$Info. SourceDataLine format) #^SourceDataLine line (AudioSystem/getLine info)] (doto line (.open format) (.start)) (let [buf (byte-array 1024)] (loop [] (let [nb (.read in-stream buf 0, (alength buf))] (when (>= nb 0) (.write line buf 0 (alength buf))) (when (not= nb -1) (recur)))) (doto line (.drain) (.close))))) (defn async-play [filepath] (future (play filepath)))
async の方はスレッドで再生する
(play "meow.wav") (async-play "meow.wav")
30回ならしたりするとちょっと楽しかった
(take 30 (repeatedly #(async-play "buiin.wav")))