I'm looking for an easy to program library for infrequently playing sounds (notifications and the like) from a clojure function.
edit: like this
(use 'my.sound.lib')
(play-file "filename")
(beep-loudly)
(bark-like-a-dog)
...
OK, with the question now including an API wishlist... ;-)
You can use JLayer for MP3 playback on the JVM. On Ubuntu it's packaged up as libjlayer-java. There's a simple example of use in Java here. A Clojure wrapper:
(defn play-file [filename & opts]
(let [fis (java.io.FileInputStream. filename)
bis (java.io.BufferedInputStream. fis)
player (javazoom.jl.player.Player. bis)]
(if-let [synchronously (first opts)]
(doto player
(.play)
(.close))
(.start (Thread. #(doto player (.play) (.close)))))))
Use (play-file "/path/to/file.mp3")
to play back an mp3 fly in a separate thread, (play-file "/path/to/file.mp3" true)
if you'd prefer to play it on the current thread instead. Tweak to your liking. Supply your own loud beep and barking dog mp3. ;-)
For a load beep and the like, you could also use MIDI... Perhaps this blog entry will be helpful if you choose to try.
Also, the link from my original answer may still be helpful in your tweaking: Java Sound Resources: Links.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With