grails - Generate an Audio waveform in Groovy -
is there way generate audio waveform using groovy? or there third party libraries allows generate audio waveforms using groovy.
you can generate , play waveform using java audio (converted 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() } }
however, you've tagged question grails, assume don't want play it?
Comments
Post a Comment