问题
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?
回答1:
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.
回答2:
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.
回答3:
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.
来源:https://stackoverflow.com/questions/23148160/how-to-play-any-waveforms-audio-in-julia-language