Using Ecasound with Unix Pipes and Stdin/Stdout

Ecasound is a versatile command-line audio processor and multitrack recorder designed to fit naturally into the Unix philosophy of chaining modular tools. By supporting standard input (stdin), standard output (stdout), and named pipes (FIFOs), Ecasound allows users to ingest dynamic data from external software, apply real-time effects or mixing, and export streams directly to encoders, media players, or remote networks without writing temporary files to disk.

Direct Stdin and Stdout Syntax

Ecasound recognizes stdin and stdout as dedicated targets for its input (-i) and output (-o) arguments. Instead of specifying a file path or an ALSA/JACK hardware device, you supply the keyword directly:

For example, to play a raw stream generated by another program using ALSA through Ecasound:

cat audio.raw | ecasound -f:s16_le,2,44100 -i stdin -o alsa

Conversely, to process an existing audio file and stream the result to an external tool like lame for MP3 encoding:

ecasound -i input.wav -efl:1000 -o stdout | lame - output.mp3

Format Specification for Headerless Streams

When piping audio through standard Unix streams, container metadata (such as WAV or AIFF headers) is often omitted or stripped, leaving raw Pulse Code Modulation (PCM) data. Ecasound cannot guess the parameters of raw streams and will throw an error if they are unspecified.

To resolve this, define the audio format using the -f flag immediately before the target:

-f:sample_format,channels,sample_rate

Common sample format tokens include:

If both input and output use pipes without headers, declare the format for each respective stream:

ffmpeg -i source.m4a -f s16le -ac 2 -ar 48000 - | \
ecasound -f:s16_le,2,48000 -i stdin -ea:150 -f:s16_le,2,48000 -o stdout | \
aplay -f cd -

Named Pipes (FIFOs)

Beyond standard file descriptors (0 and 1), Ecasound interacts seamlessly with POSIX named pipes created via mkfifo. Named pipes allow asynchronous, multi-process communication across separate terminal sessions or background scripts.

mkfifo /tmp/audio_pipe
ecasound -i /tmp/audio_pipe -o alsa

Ecasound accesses named pipes using standard file paths (-i /path/to/fifo or -o /path/to/fifo). If the pipe carries raw audio without headers, append the -f parameter just as you would with stdin.

Buffering and Real-Time Execution

Piping audio between processes can cause buffer overruns or underruns (xruns) if processing speeds fluctuate. Ecasound controls its internal engine buffer via the -b:buffersize option:

When integrating with Unix pipes, ensuring that adjacent utilities use unbuffered or block-buffered I/O prevents pipeline stalls. If output truncates prematurely, configuring Ecasound to run for a specific duration (-t:seconds) ensures predictable pipeline termination.