Batch Scripts with other programs

Effects, Recipes, Interfacing with other software, etc.

If you require help using Audacity, or think you have found a "bug", please post on the forum board relevant to your operating system.
Windows
Mac OS X
GNU/Linux and Unix-like

Batch Scripts with other programs

Permanent link to this post Posted by steve » Mon Feb 21, 2011 2:53 pm

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.
steve
Senior Forum Staff
 
Posts: 34062
Joined: Sat Dec 01, 2007 11:43 am

Add 10% silence to start of files

Permanent link to this post Posted by steve » Mon Feb 21, 2011 2:58 pm

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.

Code: Select all
#!/bin/bash

## 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"
fi

# start loop
for filename in *.wav
  do
    # 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"
  done

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

9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
steve
Senior Forum Staff
 
Posts: 34062
Joined: Sat Dec 01, 2007 11:43 am

bash script to convert audacity labels to cue sheet

Permanent link to this post Posted by djkaboodle » Mon May 30, 2011 9:48 am

[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 - http://forum.audacityteam.org/viewtopic.php?f=21&t=551), 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
Audacity labels.txt to cue sheet converter - bash script - remove the ".txt" part and change permissions to get it working
(2.79 KiB) Downloaded 1041 times
<, 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
additional bc file to perform extra calculations - remove the ".txt" part and change permissions to get it working, and place in your home directory. (original file came from here: http://www.pixelbeat.org/)
(1.74 KiB) Downloaded 693 times
<, 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: http://www.djkaboodle.co.uk/blog/2011/may/29/burning-mixes-cd-how. Again, any corrections or improvements are appreciated.

Regards,
DJ Kaboodle.
djkaboodle
 
Posts: 1
Joined: Mon May 30, 2011 8:45 am

Re: Batch Scripts with other programs

Permanent link to this post Posted by JohanP » Mon Jan 14, 2013 12:44 pm

Thank you for SoX script steve! I searched through half of web to find it here! Lol
JohanP
 
Posts: 3
Joined: Mon Jan 14, 2013 12:37 pm

Re: Batch Scripts with other programs

Permanent link to this post Posted by steve » Mon Jan 14, 2013 5:48 pm

You're welcome. :)
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
steve
Senior Forum Staff
 
Posts: 34062
Joined: Sat Dec 01, 2007 11:43 am

Recursive processing with a bash script

Permanent link to this post Posted by steve » Tue Jun 11, 2013 7:58 am

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 (viewtopic.php?f=48&t=72838) 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
Code: Select all
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.
Attachments
sox-recursive-batch-converter.txt
(668 Bytes) Downloaded 90 times
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
steve
Senior Forum Staff
 
Posts: 34062
Joined: Sat Dec 01, 2007 11:43 am


Return to Audio Processing



Who is online

Users browsing this forum: No registered users and 9 guests