Linux – How to Pipe Anything to the Audio Output

audiolinuxpipe

How can I pipe any data to audio output? For example, i want to listen to a file — an archive, a drive backup, a program. Or I want to listen to my HDD — I vaguely remember reading something about this being possible about 7 years ago, but can't find anything now.

So, files, disk reads, even network connections — I want to be able to listen to anything. I know that it's definitely possible with Linux. How can I do it? Using Lubuntu 20.04

Best Answer

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
Related Question