How can I run an audio command on every WAV file in a folder?
Asked by
QUARTZ__SAMPLE
I'm using Composer's Desktop Project to edit audio files on macOS. I need to run the same command on a large batch of WAV files instead of entering it manually for each one. For one file, the command is `distort average soundfile.wav soundfileoutput.wav`, where `distort average` is the command, followed by the input and output filenames. Is there a Terminal loop or another simple way to process every WAV file in a folder without listing each filename in a script?
Answers
The loop works in both Bash and Zsh, so it should work directly in macOS Terminal. `${f%.wav}` removes the `.wav` extension before adding `output.wav`. If the `distort` command is not found, make sure the program is installed and either available in your PATH or call it using its full path.
Reply to this answer
You can use a shell `for` loop. First change to the folder containing the WAV files, then run: `for f in *.wav; do distort average "$f" "${f%.wav}output.wav"; done`. This runs the command once for each WAV file, preserves filenames with spaces, and creates outputs such as `soundfileoutput.wav`.
Reply to this answer
For a reusable script, put the loop in a file such as `process-audio.sh`, add `#!/usr/bin/env bash` at the top, and make it executable with `chmod u+x process-audio.sh`. Then run it from the folder containing the audio files. Test it on a few copies first so existing output files are not accidentally overwritten.
Reply to this answer
Add your answer
Answers are reviewed before publication.
QUARTZ__SAMPLE: Thatโs exactly the kind of batch command I was looking for. Including `average` and quoting the filenames clears up the syntax.