Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to play any waveform's audio in julia language?

Tags:

julia

I have a sinusoid with length 5 seconds as below:

x=sin(0:.01:2*pi*500*5);

Now I would like to hear the audio of this waveform by giving a command similar as below:

playsound(x,samplingfrequency);

It will be useful for me if I could write this audio data to a wav or mp3 file. What is the library needed and the equivalent command in julia for this functionality?

like image 210
dexterdev Avatar asked Apr 18 '14 05:04

dexterdev


3 Answers

You can use WAV.jl to encode the data in a WAV file. You can install the package via the Julia package system:

Pkg.add("WAV")

Then, use the wavwrite function to create the file:

wavwrite(data, "example.wav", Fs=8000)

There is a function (wavplay) buried in the WAV source code repository to play audio too, but it only works on Linux. I am waiting for someone to contribute windows and mac versions before I include it as part of an official version.

like image 56
Dan Avatar answered Oct 14 '22 07:10

Dan


You may play audio with https://github.com/ssfrr/AudioIO.jl

And for write/read wav https://github.com/JuliaLang/Sound.jl/blob/master/src/Sound.jl

However at this time both modules are in early stage.

like image 34
chro Avatar answered Oct 14 '22 08:10

chro


I'm a bit late here, but I also found this page, which might be of use as well. It documents a series of libraries for dealing with hardware in Julia, and contains a surprisingly lengthy list for audio/video stuff.

like image 37
Jacob Amos Avatar answered Oct 14 '22 09:10

Jacob Amos