Labels Export: using samples data instead of seconds

For obvious reasons, “Export Labels” exports in the same format as used by “Import Labels”.

To export labels using sample values you would need to write your own plug-in.
There’s a lot of information about writing Nyquist plug-ins here: https://forum.audacityteam.org/t/manuals-and-reference-material/32817/1

To read labels, you will need to use Nyquist macro commands (See: https://wiki.audacityteam.org/wiki/Nyquist_Macro_Tutorial) as that’s the only way that Nyquist can access labels.

One problem is that labels are not audio, so they don’t have a sample rate. Audacity supports having multiple audio tracks with different sample rates, so there is no clear cut answer to which sample rate to use. I think the most obvious solution would be to use the “Project Rate”, which is the sample rate used for playing, recording and exporting.

Here’s an example of how to get label times in samples.
This code may be run in the Nyquist Prompt (https://manual.audacityteam.org/man/nyquist_prompt.html) and will display the data, which you can then copy to a file.
Outputting directly to a file is a bit tricky, but can be done using the “File-Button” widget (see: https://wiki.audacityteam.org/wiki/Nyquist_File-Button_Tutorial). See the code for “Sample Data Export” for an example: https://github.com/audacity/audacity/blob/master/plug-ins/sample-data-export.ny

;type analyze
;debugflags trace

(let ((txt "")
      (rate (get '*project* 'rate))
      (label-tracks (aud-get-info "labels")))
  (dolist (labels label-tracks)
    (setf labels (second labels))
    (dolist (label labels)
      (setf txt (format nil "~a~a\t~a\t~a~%"
                        txt
                        (round (* rate (first label)))
                        (round (* rate (second label)))
                        (third label)))))
  (format t txt)
  "")