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

不打扰是莪最后的温柔 提交于 2021-02-20 06:20:12

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!