Sound.jl Documentation
Contents
Overview
The Julia module Sound.jl exports the functions sound and soundsc for playing an audio signal through a computer audio output.
Their use is designed to be similar to Matlab commands sound and soundsc to facilitate code migration.
Getting started
using Pkg
Pkg.add("Sound")Example
using Sound
S = 8192 # sampling rate in Hz
x = 0.6 * cos.(2π*(1:S÷2)*440/S)
y = 0.7 * sin.(2π*(1:S÷2)*660/S)
sound(x, S) # monophonic
sound([x y], S) # stereo
soundsc([x y], S) # scale to maximum volumePortAudio on Linux
This package is layered on top of PortAudio. Some users have reported challenges on Linux OS in overcoming security access to the microphone, with errors like PortAudioException: Device unavailable. Here is an approach that worked for one user in 2024, using Julia 1.10.2.
- Install the
alsa dev toolspackage. For a debian-based distro, usesudo apt install libasound-dev, which automatically changed the package tolibasound2-devinstead. - Download
PortAudiodirectly (not the julia package) and extract the archive. I put the directory in my home folder but I’m not sure how much it matters. - Follow the PortAudio linux build instructions up through
sudo make install - Run
sudo ldconfigto allow access to other programs (such asjulia). - Caveat: This works inconsistently and requires frequent restarts of julia.