How to pipe anything to the audio output?

I find piping things into aplay works well.

journalctl | aplay doesn't sound pretty but does work surprisingly well.

Here's an example from aplay(1):

aplay -c 1 -t raw -r 22050 -f mu_law foobar
              will play the raw file "foobar" as a 22050-Hz, mono, 8-bit, Mu-Law .au file.

It can be found as part of the alsa-utils package on debian/ubuntu.

Here's a 1-liner that I like which echos a small C program into gcc, and runs the compiled version, piping it to aplay. The result is a surprisingly nice 15-minute repeating song.

echo "g(i,x,t,o){return((3&x&(i*((3&i>>16?\"BY}6YB6$\":\"Qj}6jQ6%\")[t%8]+51)>>o))<<4);};main(i,n,s){for(i=0;;i++)putchar(g(i,1,n=i>>14,12)+g(i,s=i>>17,n^i>>13,10)+g(i,s/3,n+((i>>11)%3),10)+g(i,s/5,8+n-((i>>10)%3),9));}"|gcc -xc -&&./a.out|aplay

It was possible with /dev/dsp, which is part of OSS, which hasn't been part of the Linux kernel a very long time. It used to be as easy as cat some_file >/dev/dsp or some_program >/dev/dsp.

PulseAudio provides padsp.

padsp starts the specified program and redirects its access to OSS compatible audio devices (/dev/dsp and auxiliary devices) to a PulseAudio sound server.

(source)


Examples:

  • random data

    </dev/urandom padsp tee /dev/dsp >/dev/null
    
  • regular file

    </etc/fstab padsp tee /dev/dsp >/dev/null
    
  • network activity

    sudo tcpdump | padsp tee /dev/dsp >/dev/null
    
  • block device

    sudo cat /dev/sda | padsp tee /dev/dsp >/dev/null
    

In my Ubuntu 18.04.4 LTS padsp is from the pulseaudio-utils package.

Tags:

Linux

Audio

Pipe