Stream Audio from Ecasound to a Named Unix FIFO
Ecasound fully supports streaming processed or generated audio directly into a named Unix FIFO pipe. By routing output to a FIFO created via standard Unix utilities, Ecasound can seamlessly feed live audio into external encoders, media players, or custom scripts in real time. This article explains how to set up a named pipe, configure Ecasound to stream to it, and handle data formatting and process synchronization.
Creating the Named Pipe
Before routing audio from Ecasound, generate the FIFO using the
standard mkfifo command:
mkfifo /tmp/audio.fifoA named FIFO behaves like a regular file in the filesystem, but it functions entirely in memory without writing data to disk.
Ecasound Output Syntax
To stream to the FIFO, pass the path of the named pipe to the output
flag (-o). When piping audio through a FIFO, defining the
audio format explicitly using the -f flag is critical if
you are transmitting raw PCM data, because raw streams do not include
metadata headers.
Example command streaming an audio file as raw PCM to the FIFO:
ecasound -i input.wav -f:s16_le,2,44100 -o /tmp/audio.fifoIn this command:
-i input.wavdefines the source.-f:s16_le,2,44100specifies the format: 16-bit little-endian signed integer, 2 channels, at a 44.1 kHz sample rate.-o /tmp/audio.fifopoints to the destination named pipe.
If you stream a headered format like standard WAV
(-f:wav), Ecasound will write the RIFF/WAV header to the
pipe at startup. However, because standard WAV headers require an
explicit file size, streaming non-raw formats over a pipe can cause
downstream decoders to fail once the fixed header length is exceeded.
For continuous or indeterminate streams, raw PCM (s16_le,
f32_le) is the recommended format.
Handling Blocking and Synchronization
Unix FIFOs block execution until both a reader and a writer are connected:
- If you run the Ecasound command first, it will pause and wait at the
open syscall until a downstream process opens
/tmp/audio.fifofor reading. - If the reader terminates, Ecasound will receive a
SIGPIPEsignal and exit.
To consume the stream in real time, launch a reader concurrently in a separate shell or in the background:
aplay -t raw -f cd /tmp/audio.fifoOnce the reader opens the FIFO, Ecasound immediately begins processing and transferring audio blocks through the pipe with minimal latency.