I once in the past used to play with files by playing them as if they were raw 8bit audio, but I forgot which program can be used to do this. How can I stream, say, /dev/random to my speakers with a single command?
Asked
Active
Viewed 539 times
0
-
Is `cat file > /dev/dsp` no longer a thing? – DopeGhoti Apr 07 '21 at 15:56
-
@DopeGhoti not for me, Manjaro user here. – AnnoyinC Apr 07 '21 at 16:02
-
Does this answer your question? https://unix.stackexchange.com/a/587016/272848https://unix.stackexchange.com/a/587016/272848 – Stewart Apr 07 '21 at 16:08
-
1@DopeGhoti I think not: https://unix.stackexchange.com/a/28045/123460 – FelixJN Apr 07 '21 at 16:14
2 Answers
1
You can pipe stuff into aplay (from the alsa-utils debian package).
Example:
journalctl -f | aplay
will play some noise on your speakers whenever any service writes to the journal.
cat /dev/random | aplay
--or--
aplay /dev/random
will play random noise.
From my other answer, give this a try ;)
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
Stewart
- 12,628
- 1
- 37
- 80
0
I remembered, play is the utility. Use -t to manually override the format it is interpreted as. Usually actual file formats require a header present in the file, so use fXX or uXX or iXX "formats" for raw floating point, unsigned int, signed int sampled audio respectively. Usually play -t f32 FILENAME works well enough.
Go ahead, try some files, it'll be interesting. Most compressed files sound like noise (expected), but there's some interesting formats out there which I will let you discover on your own.
AnnoyinC
- 101
- 2
-
1
-
Thank you for posting an answer, but could you add some context so it can be understood? How would we use it? What option, if any, should be given to `-t`? I tried to do this with `play -t wav file` and got an error. – terdon Apr 07 '21 at 16:06
-
@terdon addressed! For raw audio you can use the f32, u32 or i32 "types", or the 24, 16, 8 bit versions of those types. – AnnoyinC Apr 08 '21 at 10:11