Audacity Macros

Post your questions & get help from friendly LibriVoxers
Post Reply
GrayHouse
Posts: 639
Joined: October 6th, 2012, 3:27 pm

Post by GrayHouse »

I'm just sharing a library of Audacity macros for anyone who may find them useful. The macro feature is fairly recent - it allows you to automate common tasks for an easier workflow.

Macros have been discussed elsewhere on the forum. My approach is a bit different. I'm not interested in automating the entire production and export process. To me it's better to treat each piece of audio individually.
My macros simply make common editing tasks more efficient. So all the macros here perform simple functions to speed up editing.

Some Windows users use AutoHotKey for such tasks. Macros have the advantage of working from within Audacity so you don't need an external application, and they work with all operating systems. They should also be more robust with regard to any future changes in Audacity.

Here are the macros grouped by function:

Zoom Macros
Most users have a preferred screen zoom level that they like to use. These macros take you directly to a specific zoom level (rather than having to zoom incrementally). Just choose your favourite zoom levels and attach them to shortcut keys for easier zooming in and out. After I wrote these, Audacity improved its Zoom Toggle feature which allows you to do something similar, but these macros are even more flexible.
Macro Names - all the ones that start with 'Zoom...'

Amplify Macros
These allow you to amplify or deamplify the selected audio using a single key press. They automatically adjust the selection to the nearest zero crossing. I previously wrote some Nyquist Effects that do something similar. These ones are better because they add the zero crossing feature. Caution - the Amplify macros won't stop you from clipping your audio.
Macro Names - all the ones that start with 'Amplify...'

Selection Macros
These allow you to expand or contract the current selection by a small amount (the amount depends on your zoom level). For me, it's useful for editing out short noises - place your cursor on the noise and hit the 'expand' key a few times to 'grow' a selection around the cursor, then Delete or Amplify or whatever you want to do. It saves fiddly mouse operations. These may also be useful if you're working on a device without a mouse which can make it difficult to make fine selections.
Macro Names:
- Selection Expand
- Selection Contract
Note 1: There's a slight bug in Audacity which means the selection doesn't expand perfectly symmetrically. I've used an imperfect workaround to fix this.
Note 2: If you want functions to expand/contract the selection on one side only, those already exist in Audacity on the Extra >> Selection menu. You may need to use Edit >> Preferences >> Interface >> 'Show extra menus' option to enable that menu. On recent Audacity versions you can also use View >> Extra Menus (on/off)

General Editing Macros
Macro Names:
- Delete Play - deletes the selected audio (adjusts to zero crossing) and then moves the cursor back two seconds and plays from that point, so you can verify the edit and carry on listening.
- Delete Zero - I now use this instead of the standard delete function. It adjusts the current selection to the nearest zero crossing and deletes it. That's nothing radical, but it saves a key press, and I find it surprisingly useful.

Repair Macros
The Audacity Repair function is useful for making small repairs eg removing small clicks and very short mouth noises in the middle of speech. It doesn't delete anything, it just fixes the audio in-place. I use it a lot. It only works on very small sample lengths (up to 127 sample points) so you have to zoom in and carefully make a short selection around the click which can be fiddly and slow. These macros automate the selection and repair process. You just place your cursor on the centre of the problem audio (don't select anything). The macro does the selection and repair, so it's much quicker.
Macro Names:
- Repair short - place your cursor in the centre of the problem audio and run the macro. The selection is changed to show the treated audio (ie 127 samples).
- Repair Play - same as Repair short. But after doing the repair it moves the cursor back two seconds and plays from that point, so you can verify the repaired audio and carry on listening.
Side note: It's worth getting to know the Repair function, if you don't use it already. Screenshots of before and after using the effect, to show what it can do.

Spectral Editing
I've started to use this feature as an easier way to find and remove mouth clicks within words. Consider this experimental - the parameters may need tuning.
Macro names:
- Display Spectral - changes the waveform view to Multi-view ie both regular waveform and spectrogram display
- Display Waveform - change back to waveform-only view.
- Click (spectral) - remove (or reduce) a click in the selected audio. You need to be in Spectrogram (or multi-view) to use this macro, or it will generate an error. Select a short length of audio (containing the click) and apply the macro.

How do you install the macros?
They're in a zip file here. Unzip the file and copy all the .txt files (or just the ones you want) to your Audacity Macros folder. That's NOT in the normal Audacity install folder. To find its location use Help >> About Audacity, then click on the Build Information tab and find the 'Settings folder'.
On Windows it's something like C:\Users\<your windows user name>\AppData\Roaming\Audacity. There should be a folder called Macros. Unzip the file and copy the individual files to the Macros folder.
On Linux it may be under your Home directory - look for a directory called .audacity-data which should contain the Macros directory.

How do you use them?
After installing them, they should appear on the Tools >> Apply Macro menu. You can run them by clicking on the macro name in the menu.

How do you define shortcut keys?
If you like a particular macro you can assign it to a shortcut key which makes it much quicker to use.
Some Audacity versions allow you to shift-click on the macro name in the menu which takes you directly to the shortcut keys screen.
If shift-click doesn't work in your Audacity then use Edit >> Preferences... >> Keyboard to assign keys.
Either way, select the macro name, type your preferred key in the lower text box and press the Set button.
Remember you can assign 'plain' keys - you don't have to use Shift or Ctrl combinations. I use plain keys for all the common editing tasks.
I assign most keys to the left hand side of the keyboard (so they fall under my non-mouse hand) and I have related functions next to each other, so I have Selection Expand/Contract and Delete Zero on adjacent home keys which makes it easy to quickly select a short click/noise and delete it.

Other Thoughts
You probably won't use all of these macros. Choose the ones that suit your working methods. You can delete any that you don't use to save on menu clutter. Either delete the files from the Macros folder, or use Tools >> Macros >> Select a macro >> Remove
You can look at my macros to see how they work, and use them as a starting point for making your own macros. It's all quite easy.
If you have any good ideas for macros but you're not sure how to create them then post your thoughts here.
I'm using Audacity version 3.1.3. Menu items change between versions, so you may have to search on the menus if your Audacity looks different.

I hope a few people find these useful...
Post Reply