Liking cljdoc? Tell your friends :D


Idiomatic Clojure wrapper for the Java Sound API.

It's a work in progress...



Playing a wave file.

(play (->stream "~/test.wav"))

Playing a MP3 file, this example requires some extra libraries, see "Installation" below.

(-> (->stream "~/test.mp3") decode play)

Decoding a MP3 file and writing it to a WAVE file.

(-> (->stream "~/test.mp3") decode (write :wave "~/test.wav"))

Skipping Audio Streams (experimental)

Skipping a specific amount of bytes.

(-> (->stream "~/test.mp3") (skip 1000) decode play)

Skipping a stream with a ratio of its length.

(let [s (->stream "~/test.mp3")
      skip (skipper s)]
  (skip 0.5)
  (-> s decode play))

Synthesizing Sounds (experimental)

Playing the resulting stream from applying the identity function from 0 to 99999. The given function output will be converted to bytes.

(play (->stream identity 100000))

Advanced Example

A simple headless MP3 player that support a basic set of command: play, stop, pause, next, previous, random and close. To use it, you'll need some external libraries as explained below. It should work for any file format given the corresponding SPI and adding their extensions to music-file-extensions.

Known Issues

  • Skipping an encoded stream then writing its decoded output to a file using the write function will produce an empty file.


It's too early for having a distribution right now, so the best way to get clj-audio is to clone this repository and build the project using Leiningen. I'll eventually put everything in Clojars for more convenience.

For encoded file type support, you'll need to add the corresponding Service Provider Interface (SPI) which are simple jar files. First you'll have to get the Tritonus plug-ins shared classes (tritonus_share-*.jar) which is needed by most JSA's SPI. Then to get MP3 support for example, you can grab the latest versions of JLayer and MP3SPI.


Copyright (c) Nicolas Buduroi. All rights reserved.

The use and distribution terms for this software are covered by the Eclipse Public License 1.0 which can be found in the file epl-v10.html at the root of this distribution. By using this software in any fashion, you are agreeing to be bound by the terms of this license.

You must not remove this notice, or any other, from this software.

Can you improve this documentation?Edit on GitHub

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close