Skip to content

Instantly share code, notes, and snippets.

@angerman
Created October 4, 2009 14:16
Show Gist options
  • Save angerman/201412 to your computer and use it in GitHub Desktop.
Save angerman/201412 to your computer and use it in GitHub Desktop.
(import [javax.sound.sampled AudioSystem DataLine$Info SourceDataLine])
(defn audio-copy [input output] ;; copy-n-past from duck-streams 'copy
(let [buffer (make-array Byte/TYPE *buffer-size*)]
(loop []
(let [size (.read input buffer)]
(when (pos? size)
(do (.write output buffer 0 size)
(recur)))))))
(defn play [#^File t]
(let [stream (AudioSystem/getAudioInputStream t)
format (.getFormat stream)
info (DataLine$Info. SourceDataLine format)
line (AudioSystem/getLine info)]
(doto line
(.open format)
(.start))
(audio-copy stream line)
(doto line
(.drain)
(.close))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment