2010-01-19 9 views

回答

8

OK,用現在的問題包括API心願... ;-)

您可以使用JLayer有關JVM MP3播放。在Ubuntu上它被打包成libjlayer-java。 Java here中有一個簡單的例子。一個Clojure的包裝:

(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))))))) 

使用(play-file "/path/to/file.mp3")播放一首mp3飛在一個單獨的線程,(play-file "/path/to/file.mp3" true)如果你願意發揮它在當前線程來代替。根據你的喜好調整。提供你自己的響亮的嘟嘟聲和狗叫聲mp3。 ;-)

對於負載嘟嘟聲等,你也可以使用MIDI ...也許這blog entry將是有幫助的,如果你選擇嘗試。

另外,從我原來的答案鏈接可能仍然有助於你的調整:Java Sound Resources: Links

0

自2010年以來,至少出現了三個用於音頻回放,操縱,可視化和保存的庫。

clj-audio

構建在Java Sound API之上的通用音頻庫。具有最小量的依賴關係,但項目看起來相當放棄。

參考在project.clj(第二個需要播放MP3文件):

[org.clojars.beppu/clj-audio "0.3.0"] 
[com.googlecode.soundlibs/mp3spi "1.9.5.4"] 

用例:

(require '[clj-audio.core :refer :all]) 

;; Play an MP3 file 
(-> (->stream "bell.mp3") 
    decode 
    play) 

;; Playing synthesized sounds is an experimental feature for the library 

更多細節:https://github.com/beppu/clj-audio

Dynne

甲簡單易用的選擇。有大量的依賴關係。

參考在project.clj

[org.craigandera/dynne "0.4.1"] 

用例:

(require '[dynne.sampled-sound :refer :all]) 

;; Play an MP3 file 
(play (read-sound "bell.mp3")) 

;; Play a synthesized sound 
(play (sinusoid 1.0 440)) 

更多細節:https://github.com/candera/dynne

泛音

它依賴於SuperCollider合成引擎的高級選項。我想這只是玩玩通知而已,但爲了完整起見,我在這裏提到它。

更多詳細信息:https://github.com/overtone/overtone