How can I run an audio command on every WAV file in a folder?

0
0
Asked By MellowPine47 On

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?

3 Answers

Answered By SilverOak29 On

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.

Answered By BrightKite82 On

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`.

MellowPine47 -

That’s exactly the kind of batch command I was looking for. Including `average` and quoting the filenames clears up the syntax.

Answered By QuietMarble6 On

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.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.