Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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.

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top