Insert audio clip into track at regular intervals

Questions, discussion and recipes for scripting and batch processing in Audacity.
See also the "Scripting" section of the Audacity manual.
Forum rules
If you require help using Audacity, please post on the forum board relevant to your operating system:
Mac OS X
GNU/Linux and Unix-like
Post Reply
Site Admin
Posts: 81922
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Insert audio clip into track at regular intervals

Post by steve » Mon Feb 01, 2021 5:45 pm

The task:
You have a long file and you want to insert an audio clip multiple times into the long track at regular intervals.
For example, you may have a short clip containing the word "Demo" that you want to insert every 30 seconds.

This code can be run from the Nyquist Prompt:

Code: Select all

;type tool
(setf interval 2.5)  ;interval in seconds.
(let ((end (get '*selection* 'end)))
  (setf end (* interval (truncate (/ end interval))))
  (when (= end (get '*selection* 'end))
    (setf end (- end interval)))
  (do ((t0 end (- t0 interval))
       (i 0 (1+ i)))
      ((or (> i 10)(<= t0 0)))
    (aud-do (format nil "SelectTime: start=~s end=~s"
                    t0 t0))
    (aud-do "Paste:")))

To use the code:

1. Select and copy the audio clip that will be inserted.
2. Select the long track
3. Run the code.
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

Post Reply