aplay piping to arecord using a file instead of stdin and stdout

人盡茶涼 提交于 2019-12-14 03:06:22

问题


Below command will record the data from default device and output it on stdout and aplay will play the data from stdin.

arecord -D hw:0  | aplay -D hw:1 -

Why we prefer stdin and stdout instead of writing into a file and reading from it as below?

arecord -D hw:0 test.wav | aplay -D hw:1 test.wav

回答1:


Using a pipe for this operation is more efficient and effective than using a file, simply because of the following reasons:

1) Pipe (|) is an interprocess communication technique. The output of one process is directly sent to the input of another process using a kernel-based buffer. So this gives faster speed than writing something to a file in hard disk and reading it from it. This depends however on other factors also. Generally, the kernel also writes and reads small files from buffers and disk caches.

2) Using interprocess communication technique also helps in getting concurrent operation. Instead, if you had to write something to a file and then read from it, it would have to be performed in steps, so you would have lost the concurrency.

I assume you meant

arecord -D hw:0 test.wav && aplay -D hw:1 test.wav

instead of

arecord -D hw:0 test.wav | aplay -D hw:1 test.wav


来源:https://stackoverflow.com/questions/50747375/aplay-piping-to-arecord-using-a-file-instead-of-stdin-and-stdout

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!