Ok recycling a comment from a while back but it still holds true that I could not believe after decades of using Linux it had never even occurred to me that this was possible.
The Original title was
Why Linux is just so Cool
OK I already know Linux is just the best OS bar none but it is only when you stumble across something that is inherent in Linux that will work on any platform and is just so damn useful you have to think to yourself “Wow man! Linux is cool”
So my little gem is Linux and the standard device. Now we all know stdout and stdin and probably have used it in pipe form for ages
cat <file> | grep <string>
But what you may not know is that the standard output can also be accessed through the filesystem at /dev/stdout and /dev/stdin. Go on look yourself, they are there by default. What this means is that programs that don’t have stdout support can be made to work anyway.
In my example I am using the PicoTTS tools which should be available on most distributions. However the syntax for the command is very limited.
Usage: pico2wave <words>
-w, --wave=filename.wav Write output to this WAV file (extension SHOULD be .wav)
-l, --lang=lang Language (default: "en-US")
-?, --help Show this help message
--usage Display brief usage message
So standard tricks will not work:
pico2wave -w out.wav "Test me"| aplay -
aplay: playback:2715: read error`
Bummer. I don’t want to have to make things more complicated and write a file and then have to read it back again with aplay.
But there is a neat trick you can use. If you symlink
/dev/stdout to a file the program can access, writing to that file will automatically be directed to stdout.
:$~ ls -la /tmp/pipe.wav
lrwxrwxrwx 1 root root 11 Jan 21 10:53 /tmp/pipe.wav -> /dev/stdout
so now you can use that as the destination file:
pico2wave -w /tmp/pipe.wav "Test me"| aplay -
Playing WAVE 'stdin' : Signed 16 bit Little Endian, Rate 16000 Hz, Mono
WooHoo! it works. And not only that you are not even writing to the disk so it could be a R/O filesystem and still work. This is how I managed to put text to speech on my raspberry pi clock with a very small footprint. It is fast, configurable and perfect for little projects you want to talk to you.
Well just thought I would share this with the LAS crowd because I know many of you are new to Linux and even if you are not tricks like that you may not be aware of. Remember it can concatenate anything to stdout. So can be a bitmap or an mp3 or anything you need as a stream of data.
Maybe that will qualify?