This is tricky in the current version of Audacity. "GetInfo:" is the only way to directly get data from Audacity back to Python, and currently there isn't a GetInfo: option to get the selection time (or even the cursor position).
You can do this with a Nyquist plug-in, but it's a bit messy.
Try this in the Nyquist Prompt:
Code: Select all
;type analyze
; get start and end times
(setf sel-start (get '*selection* 'start))
(setf sel-end (get '*selection* 'end))
;print the results
(format nil "Start = ~a End = ~a" sel-start sel-end)
The format for returning labels is "a list of lists", where each inner list is in the format:
(start-seconds end-seconds label-text)
The start and end times are relative to the selection start.
Example - label the current selection:
Code: Select all
;type analyze
(setf start (get '*selection* 'start))
(setf end (get '*selection* 'end))
;calculate the length
(setf duration (- end start))
; make the label.
; Relative start time = 0
; Relative end time = duration
(list (list 0 duration "Label Text"))