How to Read Audio from Stdin in Ecasound

This article explores Ecasound's support for reading audio streams through standard input using the stdin device. It details how Ecasound handles piped audio data from the command line, outlines the required syntax and formatting arguments, and provides practical examples for integrating Ecasound into dynamic audio processing workflows.

Does Ecasound Support Stdin?

Yes, Ecasound fully supports reading audio streams from standard input. It designates stdin as a valid input audio object, allowing users to pipe raw or formatted audio directly from other utilities—such as FFmpeg, SoX, or ALSA capture tools—into Ecasound for real-time processing, filtering, or routing.

Basic Syntax

To use standard input as an audio source in Ecasound, specify stdin (or -i stdin) as the input argument:

ecasound -i stdin -o default

Or using standard Unix pipes:

command_producing_audio | ecasound -i stdin -o alsa

Specifying Stream Formats

When reading from standard input, Ecasound often requires explicit audio format settings unless the incoming data contains readable header information (such as a RIFF WAV stream). If raw PCM data is piped into stdin, you must define the stream parameters using the -f flag before declaring the input:

cat raw_audio.pcm | ecasound -f:s16_le,2,44100 -i stdin -o default

In the format parameter -f:format,channels,sample_rate:

Practical Example: Piped Decoding

A common use case involves decoding an unsupported or remote audio stream with FFmpeg and processing the audio in Ecasound:

ffmpeg -i input.mp3 -f wav - | ecasound -i stdin -o default

Because FFmpeg outputs a valid WAV stream containing header metadata, Ecasound automatically detects the sample rate, bit depth, and channel count without requiring manual format declarations.

Important Considerations