Scripting Ecasound Interactive Mode via Stdin
Ecasound fully supports feeding batch command scripts directly into
its interactive mode using standard input (stdin). By
invoking Ecasound with the interactive mode flag (-c), the
engine continuously reads text-based instructions from the input stream,
allowing you to automate multitrack processing, effect parameters, and
routing. Using standard UNIX streams, redirection, pipes, and
here-documents enables non-interactive, programmatic execution of
Ecasound Control Interface (ECI) commands.
How Ecasound Handles Interactive Stdin
When launched with the -c option, Ecasound starts in
interactive mode and listens for ECI commands via standard input. Rather
than manually typing commands into the terminal prompt, you can pipe or
redirect a pre-written text file containing sequential commands directly
into the process.
Methods for Passing Batch Commands
1. Input Redirection
You can store your commands in a plain text file (commonly with a
.eci extension) and pass it directly to Ecasound using
shell redirection:
ecasound -c < batch_commands.eci2. Using Standard Pipes
If commands need to be generated dynamically by another process, you can pipe standard output straight to Ecasound:
cat batch_commands.eci | ecasound -cOr generate single, sequential commands inline:
printf "cs-add play_chain\nai-add input.wav\nao-add /dev/dsp\nstart\nsleep 5\nstop\nquit\n" | ecasound -c3. Bash Here-Documents
For standalone shell scripts, embedding commands directly within a
here-document avoids the need for external .eci files:
ecasound -c <<EOF
cs-add session1
c-add chain1
ai-add audio_track.wav
ao-add alsa
start
int-cmd-sleep 10
stop
quit
EOFEssential Scripting Guidelines
- Terminating the Process: Always ensure the batch
script ends with the
quitcommand. Because stdin is redirected, failing to issuequitor close the stream may leave the process hanging or terminate abruptly without flushing audio buffers. - Managing Playback Duration: Since Ecasound
processes batch inputs sequentially at machine speed, playback commands
like
startneed time to execute before receivingstoporquit. Use Ecasound's built-in timing commands—such assleep <seconds>orint-cmd-sleep <seconds>—to allow playback or recording to run for the desired length of time. - Error Handling: Ecasound interactive mode will attempt to continue parsing input even if an invalid command is encountered. Ensure command sequences are validated beforehand to prevent unintended routing or incomplete audio rendering.