Advertisement
Guest User

audacity_pause_replacement

a guest
Jun 16th, 2025
16
0
363 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.20 KB | Software | 0 0
  1. # Source: https://clck.ru/3GeqYu
  2. # Path to your files
  3. labels_file = "/path/to/audacity_labels.txt"  # Path to the labels file
  4. room_tone_file = "/path/to/room-tone/audio.wav"  # Path to the room tone audio file
  5. output_macro = "/path/to/macro.txt"  # The macro file we'll create
  6.  
  7. # Read labels
  8. labels = []
  9. with open(labels_file, "r") as f:
  10.     for line in f:
  11.         parts = line.strip().split('\t')
  12.         if len(parts) >= 3:
  13.             start, end = float(parts[0]), float(parts[1])
  14.             labels.append((start, end))
  15.  
  16. # Sort labels by start time in reverse order (to avoid timestamp shifting)
  17. labels.sort(reverse=True)
  18.  
  19. # Create the macro file
  20. with open(output_macro, "w") as macro:
  21.     # Import the room tone to a new track (this will become track 1)
  22.     macro.write(f'Import2: Filename="{room_tone_file}"\n')
  23.    
  24.     # Select the room tone track (track 1)
  25.     macro.write('SelectTracks: Track=1\n')
  26.    
  27.     # Select the entire duration of the room tone track
  28.     macro.write('SelTrackStartToEnd:\n')  # Select from start to end of the track
  29.     macro.write('Copy:\n')  # Copy the selected audio (room tone) to the clipboard
  30.    
  31.     # Delete the room tone track since we just needed to copy it
  32.     macro.write('RemoveTracks:\n')
  33.    
  34.     # Process each pause from end to beginning (to avoid shifting timestamps)
  35.     for start, end in labels:
  36.         # Adjust the start and end times to avoid overlap
  37.         adjusted_start = start + 0.045  # Add 35 milliseconds to the start time
  38.         adjusted_end = end - 0.045  # Subtract 35 milliseconds from the end time
  39.        
  40.         # Select the adjusted pause in the main track (which is now track 0 after removing the room tone track)
  41.         macro.write('SelectTracks: Track=0\n')
  42.         macro.write(f'Select: Start={adjusted_start} End={adjusted_end}\n')
  43.        
  44.         # Delete the adjusted pause
  45.         macro.write('Delete:\n')
  46.        
  47.         # Paste the room tone into the main track
  48.         macro.write('Paste:\n')
  49.  
  50. print(f"Macro file created: {output_macro}")
  51. print("To use this macro in Audacity:")
  52. print("1. Go to Tools > Macros")
  53. print("2. Click 'Import'")
  54. print("3. Select the generated macro file")
  55. print("4. Run the macro")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement