Below is a primitive yet working Python script I’ve finally come up with after some more trial and error, with huge back-and-forth support from Deepseek AI.
Basically, it creates a macro named Room Tone.txt
to be run from Audacity to (semi-)automate the track import, selection, copying, and pasting operations. But first, you’ll need to:
- enable scripting in Audacity
- label the regions you want to replace with room tone in your main audio file (
audio.wav
), then - export the labels to a separate text file, e.g.,
labels.txt
, then - import the macro created by my script to Audacity
- make sure all the files (
pause.wav
andlabels.txt
) are in the same directory.
The script needs some tweaking hear and there, particularly some manual work with label fixing, file names and paths, your job priorities, etc., but it works okay.
How Script Works
-
Import Files:
- The room tone file (
pause.wav
) is imported into Audacity.
- The room tone file (
-
Select and Copy Room Tone:
- The room tone track (track 1) is selected.
- The
SelTrackStartToEnd
command selects the entire duration of the room tone track. - The
Copy
command copies the selected room tone to the clipboard. - The room tone track is then deleted since it’s no longer needed.
-
Replace Pauses:
- For each pause defined in
labels.txt
, the macro:- Extends and shortens the start and end of each label to avoid possible overlaps. You can also experiment with crossfading, as pointed here.
- Selects the pause in the main track.
- Deletes the pause.
- Pastes the room tone in its place.
- For each pause defined in
-
Save the Project:
- The
Export2
command saves the project asaudio_edited.wav
in the same directory as the originalaudio.wav
file.
- The
Hope it helps!