Skip to content

Instantly share code, notes, and snippets.

@olenhad
Created December 16, 2012 17:05
Show Gist options
  • Save olenhad/4309581 to your computer and use it in GitHub Desktop.
Save olenhad/4309581 to your computer and use it in GitHub Desktop.
Simple wav player using java sound
(ns sound.core
(:import (java.io File)
(javax.sound.sampled AudioFormat AudioInputStream AudioSystem DataLine DataLine$Info LineUnavailableException SourceDataLine)))
(defn play-sound [filename]
(let
[
sfile (new File filename)
ainput (AudioSystem/getAudioInputStream sfile)
aformat (.getFormat ainput)
info (DataLine$Info. SourceDataLine aformat)
line (AudioSystem/getLine info)
data (byte-array 128000)
]
(do
(.open line aformat)
(.start line)
(while (not= -1 (.read ainput data 0 128000))
(.write line data 0 128000))
(.drain line)
(.close line)
)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment