Macro to do Analyze -> Label sounds on a batch of files

I’m trying to create a macro to apply to a folder of files that will open each file, label sounds using the preset parameters, and save the project (so that I can go and “Export multiple” manually afterwards).

I can’t get the “Save” step to work - I get error warnings because of duplicate filenames, and I don’t know how to get Audacity to give default filenames. Any help would be appreciated.

Yes, so Audacity doesn’t really want to create an Audacity project for each input file. You can could create a macro itemizing each input file and project file:

Import2:Filename=“C:\Users\requi\Documents\Audacity\file1.mp3”
LabelSounds:measurement=“peak” post-offset=“0” pre-offset=“0” sil-dur=“0.1” snd-dur=“1” text=“Sound ###1” threshold=“-30” type=“around”
SaveProject2:AddToHistory=“0” Filename=“C:\Users\requi\Documents\Audacity\file1.aup3”
Undo:
Import2:Filename=“C:\Users\requi\Documents\Audacity\file2.mp3”
LabelSounds:measurement=“peak” post-offset=“0” pre-offset=“0” sil-dur=“0.1” snd-dur=“1” text=“Sound ###1” threshold=“-30” type=“around”
SaveProject2:AddToHistory=“0” Filename=“C:\Users\requi\Documents\Audacity\file2.aup3”
Undo:
Import2:Filename=“C:\Users\requi\Documents\Audacity\file3.mp3”
LabelSounds:measurement=“peak” post-offset=“0” pre-offset=“0” sil-dur=“0.1” snd-dur=“1” text=“Sound ###1” threshold=“-30” type=“around”
SaveProject2:AddToHistory=“0” Filename=“C:\Users\requi\Documents\Audacity\file3.aup3”

This macro would go in your AppData\Roaming\audacity\Macros directory along with all of your other macros.

Thanks so much!

I need to do this for ca. 238 files. Is there a way to run the macro on the contents of a folder without having to specify the name of each .mp3 file and corresponding .aup file?

No. Not directly with Audacity.

But you could use the above to create a script file model, from which you could create a script (macro) file. I haven’t done this in a while, but your ScriptModel.bat might be 4 lines looking roughly like this:

echo Import2:Filename=“C:\Users\yourname\Desktop\DataDirectory%1” >> log.txt
echo LabelSounds:measurement=“peak” post-offset=“0” pre-offset=“0” sil-dur=“0.1” snd-dur=“1” text=“Sound ###1” threshold=“-30” type=“around” >> log.txt
echo SaveProject2:AddToHistory=“0” Filename=“C:\Users\yourname\Desktop\DataDirectory%1.aup3” >> log.txt
echo Undo: >> log.txt

Save that model as ScriptModel.bat in your C:\Users\yourname\Desktop\DataDirectory (where your .mp3 files are located), and use WindowsKey-R, cmd, then cd Desktop and cd DataDirectory to move to your c:\Users\yourname\Desktop\DataDirectory. Type “for %a in (*.mp3) do ScriptModel %a” to create a log.txt file which contains all of your automation. Check it out to make sure everything is spelled correctly, then rename it to MyAutomation.txt and save it to C:\Users\yourname\AppData\Roaming\Audacity\macros. Then start Audacity and run it. (Backup your files first!)

A few words of caution: Before running the full script, test it out and time it with just a few files first just to make sure it is doing everything correctly. And have Task Manager ready already running just in case you decide you need to abort the script while it is running - Audacity macros can be difficult to stop once they get started.

Thanks! The script runs, and it creates the .aup files, but Audacity gives the error message “Connection to project file is null”, and when I open one of the .aup files that is produced, the project is empty. Any idea why this might be the case?

Try stripping the macro down to the first 4 lines and see how that runs. If there are problems, take it one line at a time.

This topic was automatically closed after 30 days. New replies are no longer allowed.