Batch Scripts with other programs

I’m making this thread as a location for anyone wanting to submit any batch scripts for audio processing with other audio applications.

Examples might be batch converting files to WAV using Lame with a cmd or Powershell script (Windows), or batch converting using a Python script with pacpl (Pear Audio Converter - Linux).

Please state the program and scripting language used in the script, plus a description of what the script does.
Add other details as appropriate.

Applications: SoX, Soxi, bc
Platform: Linux
Scripting language: Bash

Here’s a batch processing script that will add a period of silence to the beginning of each WAV file in a folder and place the output files in an output folder.
It could be easily adapted to add a fixed number of second of silence to the beginning or end of each file.
For different file formats, provided they are supported by SoX, simply change the file extension at the start of the loop.


## script to add 10% silence to beginning of each WAV track in current folder

if [ -d "output" ]
  then echo "Folder already exists"
  else mkdir "output"

# start loop
for filename in *.wav
    # get file properties
    slength=$(soxi -D $filename)
    schan=$(soxi -c $filename)
    srate=$(soxi -r $filename)
    # Bash only does integer arithematic, so us bc to calculate 10% length
    slength=$(echo "$slength*0.1" | bc)
    # make silence
    sox -n -c $schan -r $srate "output/temp.wav" trim 0 $slength
    # concatenate silence and file
    sox "output/temp.wav" $filename "output/$filename"

# clean up temp files
rm "output/temp.wav"
# end

[NB: this post is going to be most useful to Linux users and people who know how to convert/use a bash script]

While I am aware that there is already a great way of convert Audacity labels to cue sheets (label2cue -, I wanted something that would provide a little more information on the finished cue sheet, particularly artist and track titles. I mainly burn DJ mixes to CD, and need all the information easily available to CD-Text.

So, I wrote this bash script >
labelcue.txt (2.79 KB)
<, which will scan a folder for wav files with a labels.txt file, and convert the labels.txt file to a cue sheet. It gives interactive control over the album title and album artist, and will automatically save the cue sheet’s ‘FILE’ parameter as the name of the wav file, with ‘WAVE’ as the type. I use the same calculations as the label2cue Java program (thanks to ‘AndrewTheArt’ for authoring that), so the index times on the resulting cue sheets should be identical.

To get the bash script to run, you will need the following programs on Linux: zenity, tr, cut, bc, sed - all except zenity are likely to be part of a standard installation. However, you will also this ‘bc’ file >
bc.txt (1.74 KB)
<, uploaded to your home directory. If you upload it to another directory, you will need to change all instance of “bc ~/bc” in the bash script, replacing the tilde (~) with the full path to your home directory. Someone who knows bc better than I do might be able to make this work without the additional bc file…

If anyone can improve on or alter this script, please do so and post it up here for the benefit of others and myself. I am no bash expert, and, while I have found this works fine for me and does not do anything unpleasant, I am sure there will be the odd mistake in there. Anyway, I hope someone finds it useful.

I wrote a blog post about burning gapless mix CDs, which someone also might find useful: Again, any corrections or improvements are appreciated.

DJ Kaboodle.

Thank you for SoX script steve! I searched through half of web to find it here! Lol

You’re welcome. :slight_smile:

Applications: SoX
Platform: Linux
Scripting language: Bash

I originally wrote this for someone that wanted to change the sample rate of their entire music collection from 192 kHz to 48 kHz FLAC format ( but it could be easily adapted for other batch processing jobs where recursion through a folder hierarchy is required.

As with other scripts provided here, this comes with no guarantee of any sort and is entirely at the users risk.

Note also that this script must run in Bash and not in Dash.
Giving in a .sh extension, making it executable and then double clicking on the script file should work but if not run it from the command line with

bash filename

In its current form, the script should be run from within the top level of the folders containing the flac files.
The “output” path (near the top of the file) will need to be changed to suit the computer that it is being used on.
sox-recursive-batch-converter.txt (668 Bytes)

Thanks to djkaboodle for the labelcue script!
It took me a while to find it here… It works perfectly with K3b.
I made a small change for myself: I set $artist = $performer, because I made a cuesheet for a live performance of a band.