2010-01-19 6 views

답변

8

OK, 같은 ... ;-)

당신은 JVM에 MP3 재생에 JLayer를 사용할 수 있습니다. 우분투에서는 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")는 별도의 스레드에서 (play-file "/path/to/file.mp3" true) 비행 mp3 파일을 재생합니다. 좋아하는대로 조정하십시오. 자신의 큰 삐 소리와 짖는 개 mp3를 제공하십시오. ;-)

로드 비프와 같은 경우에는 MIDI를 사용할 수도 있습니다. 아마도이 blog entry은 시도하기로 결정하면 도움이됩니다.

내 원래 답변의 링크는 여전히 조정에 도움이 될 수 있습니다 : Java Sound Resources: Links.

0

2010 년 이래로 오디오 재생, 조작, 시각화 및 저장을 위해 최소한 세 개의 라이브러리가 나타났습니다.

CLJ-오디오

범용 오디오 라이브러리는 자바 사운드 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