Create Label for Each Clip in Track

I’m looking for a plug-in that will create a label for each clip on a particular track. For example, on track one, I have split the .wav into five pieces. Clicking on the menu item for this hypothetical plug-in it should create a corresponding label on a single label track for each clip.

If this has been built before, I’d love to hear about it.

In the meantime, I’ve been going through the board and found a smattering of create label plug-ins which I can leverage but can’t find anything to just loop through a track and identify each clip/clip boundary. I’m new to Audacity and Nyquist so I might not be using the right nonmenclature.

Any guidance you could give me would be appreciated.

I have gotten a little farther down the road. I can print out the list of clip start/end times and I can add a label but when I combine the two within a loop, it just ignores the list command (no error message). Any insight?

(setf mylist (get 'track 'clips))

(print
(dolist (x mylist)
(print x)
(list (list x “label”) )
(setf i (1+ i))))

Until recently, that would not have been possible.
In “version 4” plug-in code, you can get the times for start and end of audio clips from the TRACKS property list.
For more info, see: http://wiki.audacityteam.org/wiki/Nyquist_Plug-ins_Reference#.2ATRACK.2A

Some info about creating labels: http://wiki.audacityteam.org/wiki/Nyquist_Plug-ins_Reference#Return_Values

Is that enough? Ask if you get stuck.

Crossed posts.

You’re pretty close.
To create the labels, you need to return the specially crafted “list of lists”. You don’t need to print it.

Assuming that you are dealing with mono tracks, “mylist” in your example should look something like this:

(setf mylist (get '*track* 'clips))
(print mylist)

Debug output:

((0 1.9127) (2.84981 5.08344) (5.08344 6.53402) (7.00899 9.99998))

So this is a list containing lists with the start and end times of each clip. In fact, that is very nearly what we want.

To create labels, what we want is:
((0 1.9127 “string”) (2.84981 5.08344 “string”) (5.08344 6.53402 “string”) (7.00899 9.99998 “string”))

Because we want to modify each list within the list, it’s easier to do this with a DO loop rather than DOLIST.
I’ve added some comments to this code, but if you need clarification about it, just ask.

;version 4
(setf label-string "Clip")

(let ((cliplist (get '*track* 'clips))
      labels) ;local variable = NIL
  (do ((i 0 (1+ i)))
      ((not (nth i cliplist)) labels)  ;return value is 'labels'
    ;; create the label and push onto "labels" list
    (push (append (nth i cliplist) (list label-string))
          labels)))
1 Like

This was awesome! Thank you, Steve.

Did you understand the code? If not, I’d be happy to answer questions.
If you’d be interested in making it into an installable plug-in (that just needs a few more headers adding), and support for stereo tracks (that needs “(get 'track 'clips)” to be handled fully), then I think it could be a useful tool for other and could be uploaded to the Audacity wiki plug-ins page. No problem if not - that was just a thought :wink:

Thank you, I needed this functionality and had been using audacity/audacity-project-tools + Python. GenAI made a version that works even if the first clip does not start at 0.00:

;version 4

(let ((clips (get '*track* 'clips))           ; absolute clip positions from Audacity
      (sel-start (get '*selection* 'start))   ; selection start = 0 in Nyquist world
      labels)

  (dolist (clip clips (reverse labels))
    (let* ((abs-start (first clip))
           (abs-end   (second clip))
           (rel-start (- abs-start sel-start))  ; convert absolute to relative time
           (rel-end   (- abs-end   sel-start))
           (label-text "Clip"))                 ; simple label for all clips

      (push (list rel-start rel-end label-text)
            labels))))

Download version, Install, Launch

Download from label-clips.ny (548 Bytes)

For installation see

Usage

  1. Select any audio
  2. Analyze/Label Clips

Output example

The main thing you need for a plug-in is the required “headers”.

Unfortunately the documentation I wrote in the old Audacity wiki has gone off-line, but you can still access it from the Internet Archive: Nyquist Plug-ins Reference - Audacity Wiki

Thank you, input the source of Headers Reference | Audacity Plugins as well as the source for Nyquist Plug-ins Reference - Audacity Wiki and the code from my previous post into a GenAI and the result worked as a plugin, so I added it to the previous post. I’ll make sure to force-feed these resources in the future. I just wish the GenAI would be better at figuring out how to make code that doesn’t require audio to be selected.