As it says in this post Macro: How to make a selection relative to labels - #8 by steve
The code in my previous post is correct for Audacity 2.3.1, but requires a slight modification to work in Audacity 2.3.0.
So let’s look at what that code does:
(aud-get-info "Labels")
This command returns a list that contains information about labels in the project.
We can view the data by running this code in the Nyquist Prompt:
;type tool
(format nil "~a" (aud-get-info "Labels"))
Here’s and example for Audacity 2.3.1 or later:
((1 ((2 2 Point label track 1) (10 12 Region label track 1))) (2 ((10 12 Region label track 2))))
Rewriting that with some new lines to make it easier to read:
((1 ((2 2 Point label track 1)
(10 12 Region label track 1)))
(2 ((10 12 Region label track 2))))
The first element in the list contains a list of labels for the first label track:
(1 ((2 2 Point label track 1)
(10 12 Region label track 1)))
and the second element in the list contains a list of labels for the second label track:
(2 ((10 12 Region label track 2)))
Looking at the first label track element, we can see that it is a list of two elements.
The first is the track index (tracks are numbered starting with “0” as the top track in the project).
The second element contains the actual labels:
((2 2 Point label track 1) (10 12 Region label track 1))
In this case, there are two labels:
(2 2 Point label track 1)
; start at 2 seconds, end at 2 seconds, label text: "Point label track 1"
and
(10 12 Region label track 1)
; start at 10 seconds, end at 12 seconds, label text: "Region label track 1"
So in order to get the labels from the first label track:
The first element of (aud-get-info “Labels”) is the first label track.
(first (aud-get-info "Labels"))
The second element of the label track is the list of labels.
(second (first (aud-get-info "Labels")))