Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Source: https://clck.ru/3GeqYu
- # Path to your files
- labels_file = "/path/to/audacity_labels.txt" # Path to the labels file
- room_tone_file = "/path/to/room-tone/audio.wav" # Path to the room tone audio file
- output_macro = "/path/to/macro.txt" # The macro file we'll create
- # Read labels
- labels = []
- with open(labels_file, "r") as f:
- for line in f:
- parts = line.strip().split('\t')
- if len(parts) >= 3:
- start, end = float(parts[0]), float(parts[1])
- labels.append((start, end))
- # Sort labels by start time in reverse order (to avoid timestamp shifting)
- labels.sort(reverse=True)
- # Create the macro file
- with open(output_macro, "w") as macro:
- # Import the room tone to a new track (this will become track 1)
- macro.write(f'Import2: Filename="{room_tone_file}"\n')
- # Select the room tone track (track 1)
- macro.write('SelectTracks: Track=1\n')
- # Select the entire duration of the room tone track
- macro.write('SelTrackStartToEnd:\n') # Select from start to end of the track
- macro.write('Copy:\n') # Copy the selected audio (room tone) to the clipboard
- # Delete the room tone track since we just needed to copy it
- macro.write('RemoveTracks:\n')
- # Process each pause from end to beginning (to avoid shifting timestamps)
- for start, end in labels:
- # Adjust the start and end times to avoid overlap
- adjusted_start = start + 0.045 # Add 35 milliseconds to the start time
- adjusted_end = end - 0.045 # Subtract 35 milliseconds from the end time
- # Select the adjusted pause in the main track (which is now track 0 after removing the room tone track)
- macro.write('SelectTracks: Track=0\n')
- macro.write(f'Select: Start={adjusted_start} End={adjusted_end}\n')
- # Delete the adjusted pause
- macro.write('Delete:\n')
- # Paste the room tone into the main track
- macro.write('Paste:\n')
- print(f"Macro file created: {output_macro}")
- print("To use this macro in Audacity:")
- print("1. Go to Tools > Macros")
- print("2. Click 'Import'")
- print("3. Select the generated macro file")
- print("4. Run the macro")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement