Code Works in Nyquist Prompt, But Failed as Plugin.ny

Hi everyone, I’m trying to write a plugin that appends the duration of each label to its text. The code itself works in Nyquist Prompt and generates a new label track for me, but when I save it as a .ny file and install it with Nyquist Plugin Installer, it runs, but takes no effect. How can I fix it? Thank you if anyone can help me on this!
append-duration-to-labels.ny (1.7 KB)

BTW, I’m running Audacity 3.5.1 on Windows 11, and I write code with Notepad++.

;type process plug-ins are “effects”. An “effect” plug-in should take audio input from the selected track(s) and return audio.

type analyze plugins appear in the “Analyze” menu. An “analyze” plug-in usually (but not always) takes audio input from the selected track(s) and returns non-audio.

As you are returning labels and not audio, the plug-in needs to be an “analyze” type.

I also noticed that your plug-in only considers the first label track, and ignores any other label tracks. I have assumed that is intentional, but if you publish this plug-in you should make it clear in the documentation that is what it does.

The ;action header is now obsolete and not used by current versions of Audacity.

Here is a version that simplifies the code a bit:

;nyquist plug-in
;version 4
;type analyze
;name "Append Duration to Labels"
;release 1.0.2
;author "Steve Chow"
;info "Released under GPL v2."


(let ((labels (nth 1 (nth 0 (aud-get-info "labels")))))
  (do ((count 0 (+ 1 count)))
      ((>= count (length labels)) labels)
    (let ((start (nth 0 (nth count labels)))
          (end (nth 1 (nth count labels)))
          (text (nth 2 (nth count labels))))
      (setf text (format nil "~a (~as)" text (- end start)))
      (setf (nth 2 (nth count labels)) text))))

1 Like

I almost forgot: When you update the type of the plug, Audacity ignores that change (it is arguable if this is a bug, or a limitation, or a feature, though I would consider it a bug).

After updating the plug-in type in your code, you will need to:

  • Delete the previous version from wherever it is installed,
  • Restart Audacity.
  • install the new version.
  • Restart Audacity again.

Wow, that’s awesome, I can’t thank you more! That’s exactly what I’m looking for.
BTW, I noticed the plugin can only return on list, can I generate multiple label tracks with one list? I don’t know, that’s why I process one label track at one time.

Really? I updated the plugin with “Rescan” from “Plugin Manager”, and it looked alright. Well it worked for me at least.

That’s good to know.

It’s a pain for me to use “Rescan” as I have loads of audio plug-ins that don’t work properly with Audacity (I use them in other music software). After using “Rescan” I have to go back through the huge list, disabling all the plug-ins that I don’t use in Audacity.

I assume you mean “one list”.

Yes, Nyquist can only return one label track at a time.
It would be possible for your plug-in to read all of the label tracks, and merge them into a single label track, but it would make the plug-in a bit more complex. You would have to iterate through each track from (aud-get-info "labels"). Unless you frequently use multiple label tracks, it may not be worth the effort.