Saving a Pulse Audio stream with Haskell bindings -
using pulse-simple package have made following code:
main=do s<-simplenew nothing "example" record nothing "this example application" (samplespec (f32 littleendian) 44100 1) nothing nothing xs<-simpleread s $ 44100*10 :: io [float] simplefree s play xs play :: [float] -> io () play d = s<-simplenew nothing "example" play nothing "this example application" (samplespec (f32 littleendian) 44100 1) nothing nothing simplewrite s d simpledrain s simplefree s this works , records 10 seconds of audio , plays back.
i want encode , save audio file (as .wav rr whatever) can played in program or converted. think more of audio question non haskell people have array of floats 44100*10 long. suspect i'll need other library.
thanks in advance.
seems data.wave module wave package should job.
convert [float] [int32] , constitutes wavesamples field of wave record. fill in rest of waveheader , write file using putwavefile.
import data.wave writewavefile :: string -> [float] -> io () writewavefile path floats = putwavefile path wave wave = wave wheader wsamples wheader = waveheader { wavenumchannels = 1 , waveframerate = 44100 , wavebitspersample = 32 -- or maybe 8? , waveframes = nothing } wsamples = [[ ... | x <- floats ]] fill in ... suitable float -> int32 function.
Comments
Post a Comment