2013-05-15 93 views

回答

0

您可以生成和使用Java聲音,像這樣(converted from the java here)扮演的波形:

import javax.sound.sampled.* 

byte[] wavform(int freq, int seconds, int sampleRate) { 
    byte[] ret = new byte[ seconds * sampleRate ] 
    ret.length.times { idx -> 
    ret[ idx ] = (byte)(Math.sin((2.0 * Math.PI * idx)/(sampleRate/freq)) * 127) 
    } 
    ret 
} 

int sampleRate = 8000 
new AudioFormat(sampleRate, 16, 1, true, true).with { af -> 
    AudioSystem.getSourceDataLine(af).with { line -> 
    line.open(af) 
    line.start() 
    wavform(200, 1, sampleRate).with { byte[] wav -> 
     line.write(wav, 0, wav.length) 
    } 
    line.drain() 
    line.close() 
    } 
} 

然而,正如你已經標記了這個問題Grails的,我假設你不想玩?