0
有沒有使用Groovy生成音頻波形的方法?或者是否有任何第三方庫允許您使用groovy生成音頻波形。在Groovy中生成音頻波形
有沒有使用Groovy生成音頻波形的方法?或者是否有任何第三方庫允許您使用groovy生成音頻波形。在Groovy中生成音頻波形
您可以生成和使用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的,我假設你不想玩?
我的回答有幫助嗎? –