Macro Examples

From Audacity Wiki
Jump to: navigation, search
This page provides some examples of how the Macros feature in Audacity can be used.

Additional examples may be found in the manual.

Please try to keep simple examples at the top of each section, and more complex versions lower down.

Shortcut and Automation Scripts

These Macros are suitable for assigning to a keyboard shortcut.

They may not all be suitable for batch processing. If they are adapted for batch processing, remember to add an Export command so that the processed file is saved.


Keyboard Shortcut to Switch Track View

Audio tracks in Audacity have three display options. For some types of work it is necessary to frequently switch between the waveform view and the spectrogram view. To create a shortcut to one of the display types, simply create a Macro with one of the commands below, and create a keyboard shortcut to the Macro.

SetTrackVisuals:Display="Waveform"
SetTrackVisuals:Display="Spectrogram"
There is currently no scripting command for Waveform (dB) view.


Convert a Mono Track to a Stereo Track

This Macro assumes that there is only one mono track in the project. It is equivalent to duplicating the track and then joining the two mono tracks to create a 2 channel (stereo) track.

See also the Convert Mono Files to Stereo Files batch script.

 SelectAll:
 Copy:
 RemoveTracks:
 NewStereoTrack:
 Paste:


Select and Repair

This Macro is an enhancement of the Repair effect. The Repair effect supports a maximum selection of 128 samples. Rather than having to manually make the selection, this Macro automatically selects 1 millisecond either side of the cursor position, then applies the Repair effect. Note that it is essential that the cursor position is close to the middle of the section to be repaired and there is not an audio selection.

The total length of the repair is 2 milliseconds, which is 88 samples for a sample rate of 44100 Hz, or 96 samples for a sample rate of 48000 Hz. For higher sample rates it will be necessary to reduce the selection times.

 SelectTime:End="0.001" RelativeTo="SelectionStart" Start="-0.001"
 Repair:


Batch Processing Macros

These Macros are intended for batch processing.

Batch processing provides a way to apply a sequence of effects or edits to multiple files. The files must all be in the same directory. Batch processing Macros end with an export command.


Convert Mono Files to Stereo Files

This Macro is similar to the Convert a Mono Track to a Stereo Track example above, but is much simpler because Audacity automatically mixes down all non-muted tracks on Export. If one or more tracks are stereo, and the export format supports stereo, then the exported file will be 2 channel stereo. This example exports as WAV, though other Export commands could be used.

The exported file will still sound like a mono file because both channels are identical - there is no stereo spread.
 NewStereoTrack:
 ExportWav:


Prepend an Intro File to a Batch of Audio Files

This Macro must be customised to suit the length of the Intro file. In this example it is assumed that the Intro file is 20 seconds.

The file name in the Import2: command should be the fully qualified file name (the full path plus the name of the file. Note that on Windows, the file separator needs to be either double backslashes, or forward slashes rather than the more familiar single backslash. This example assumes that the into file is C:\Audio Files\intro.wav.

 SelectTime:End="20" RelativeTo="ProjectStart" Start="0"
 Repeat:Count="1"
 SelectTime:End="20" RelativeTo="ProjectStart" Start="0"
 Silence:Use_Preset="<Factory Defaults>"
 Import2:Filename="C:\\Audio Files\\intro.wav"
 ExportWav:


Tips and Tricks

Macros are very versatile, but it is not always obvious how to perform some operations. These example scripts provide tips for how to achieve useful functions that may at first appear to be missing from Macros.

Insert Silence at the Cursor Position

This Macro may be easily modified to insert any specified duration of silence (in this example, 2 seconds) at the cursor position (or at the start of a selection). It works by copying the specified amount of audio and repeating it one time. The selection is then reset to the same specified duration (2 seconds) after the original cursor position, and silenced.

 Select: Start="0" End="2" Mode="Set" RelativeTo="SelectionStart"
 Repeat:Count="1"
 SelectTime: Start="0" End="2" RelativeTo="SelectionStart"
 Silence:


Joining tracks to make a stereo track

This Macro is equivalent to the Make Stereo Track command in the audio track dropdown menu. In this example it is assumed that the project contains only two mono tracks.

The "trick" here is that we can select the right channel only of the stereo track as track number 2.5.

 NewStereoTrack:
 SelectTracks:Mode="Set" Track="0" TrackCount="1"
 SelTrackStartToEnd:
 Cut:
 SelectTracks:Mode="Set" Track="2"
 Paste:
 SelectTracks:Mode="Set" Track="2.5" TrackCount="0.5"
 Delete:
 SelectTracks:Mode="Set" Track="1" TrackCount="1"
 SelTrackStartToEnd:
 Cut:
 SelectTracks:Mode="Set" Track="2.5" TrackCount="0.5"
 Paste:
 SelectTracks:Mode="Set" Track="0" TrackCount="2"
 RemoveTracks:


Split Stereo Track

This Macro is equivalent to the Split Stereo Track command in the audio track dropdown menu. In this example it is assumed that the project contains only one stereo track.

 NewMonoTrack:
 NewMonoTrack:
 SelectTracks:Mode="Set" Track="0" TrackCount="0.5"
 SelTrackStartToEnd:
 Cut:
 SelectTracks:Mode="Set" Track="1" TrackCount="1"
 Paste:
 SetTrackAudio:Pan="-100"
 SelectTracks:Mode="Set" Track="0.5" TrackCount="0.5"
 SelTrackStartToEnd:
 Cut:
 SelectTracks:Mode="Set" Track="2" TrackCount="1"
 Paste:
 SetTrackAudio:Pan="100"
 SelectTracks:Mode="Set" Track="0" TrackCount="1"
 RemoveTracks: