Well, so I was reading about this raspberry pi tutorial that makes you play audio files from raspberry pi and stream them into a FM signal and something got me curious. You can stream .wav files, which is ok, but there's a command that makes it stream live audio from the microphone.

I'm curious about how it works. This is the command:

arecord -d0 -c2 -f S16_LE -r 22050 -twav -D copy | sudo ./pifm -

Well, I'm curious about how it works. I've searched and understood that arecord is a program that records audio from your microphone. It has an option where you can write the file name and it'll save the recorded file to you. But in this example, something is happening: it looks like the audio is going directly to python, live. I mean, how is this possible? Is the program arecord feeding python with sound data?

I've only seen this syntax in this command, for example:

cat file.txt | grep 'test'

which is a way of reading the file 'file.txt' but only output the lines with 'test' written in it. So, what does, in general, the symbol | mean in linux? What is happening when he does | sudo ./pifm after some program?

I really liked this possibility in linux, it's something I've never seen before. Am I right about my assumptions? Also, how does python receive this data? Is there a library for this?

  • cat file.txt | grep 'test' can be replaced with grep 'test' <file.txt (cat with a single file can almost always be removed). – roaima Apr 23 '15 at 23:23
  • It's called a pipeline. – Gilles Apr 24 '15 at 22:01

The pipe symbol | connects output from the process on its left to the input for the process on its right. It's a fundamental part of the Unix/Linux ecosystem as it allows you to build up complex operations using relatively simple (and specialist) tools.

In case it gives you a reference point, this is similar for Windows systems too, whether Powershell or DOS.

  • Very nice! But how do this program constantly feed the python? Shouldn't it record the file, and then feed the python? Is there a special technique to live feed from a program to other? I want to learn more about this. – Faby Apr 23 '15 at 23:55
  • @Faby the pipe is the "special technique". – roaima Apr 24 '15 at 22:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.