Adding random silence to the end of multiple mp3 files

This little plugin adds random silence (between 10 and 50 seconds) to the end of multiple mp3 files. It works for mono and stereo files:

(setq silence-duration (+ 10 (random 41)))

;; Sequence function
(defun sseq (sig1 sig2)
  (seq sig1 sig2))

(abs-env
  (let ((my-silence (s-rest silence-duration)))
    (multichan-expand #'sseq s my-silence)))

Thanks Steve for the help.
Append Random Silence.ny (498 Bytes)

No, no… please do take credit for the plug-on - this is your first “published” plug-in :slight_smile:
I think it is enough to just include a code comment to give credit for bits of open source code that you have used in a plug-in.

A few comments about the plug-in…

For your own use, you can do anything you like (of course), but generally for published plug-ins we try to keep the file name and the effect name reasonably short. The effect name “random silence to multiple mp3 files” is perhaps a bit long when it appears in the Effect menu, so perhaps it could be renamed as something like: “Append Random Silence”?

Related information about naming conventions:
(again, not essential for personal use, but recommended for published plug-ins and required for plug-ins that are bundled with the standard Audacity download bundle).
By convention, the ellipsis (three dots) that are commonly seen at the end of effect names (for example: “Amplify…”), indicates that there is an effect dialogue to follow. Effects that act immediately, with no dialogue (for example: “Fade In”) are named without the three dots.
Names of effects are generally capitalised (example: “Bass and Treble”)

The “version number” in the header is a bit of a strange one. While Audacity 1.3.x was current (now obsolete), the 1.3.x series were “beta” versions and 1.2.6 was the official “stable” version. Version 3 plug-ins included code that was not recognised in Audacity 1.2.x, so it was important that if the plug-in was intended to be compatible with 1.2.x, then it needed to avoid code that was not compatible with 1.2.x, and it could then be described as a “version 1” plug-in. Audacity 2.x can use version 1, 2 or 3 plug-ins. As Audacity 1.2.x and 1.3.x are now obsolete, there is little point in marking a plug-in as “version 1”, but if it is marked as “version 1” then to be correct, it needs to be compatible with the old 1.2.x and 1.3.x series.
There have been a lot of changes to Nyquist since Audacity 1.2.x, so to be sure that a plug-in is 1.2.x compatible it would need to be tested in 1.2.x. There’s not much point in doing that as 1.2.x is obsolete. My personal view is to mark all new plug-ins as version 3, indicating that they are designed for Audacity 2.x (or late 1.3.x versions).

So… for the plug-in header, I would suggest something like:

;nyquist plug-in
;version 3
;type process
;name "Append Random Silence"
;info "by goldfinger35 nReleased under GPL v2.n"

;; Based on a code snippet by Steve.
;; Released under terms of the GNU General Public License version 2:
;; http://www.gnu.org/licenses/old-licenses/gpl-2.0.html

Another though - If you wanted to make this plug-in a bit more versatile, you add controls to set the minimum and maximum added silence.
To do that, you would replace the values “10” and “41” in the code with variables, and use slider controls to set the value of those variables.

Comment from this topic: https://forum.audacityteam.org/t/adding-random-silence-to-multiple-mp3-files/29895/8

It doesn’t exactly have “no effect” (though it does not do what you want). It produces a silent error.
Debugging a plug-in that acts directly with no user interface can be tricky, especially if there is no error message (as in this case).

A little “trick” that can help, is to force the plug-in to have a user interface, then there will be a “Debug” button (as in all Nyquist plug-in interfaces). The Debug button allows you to see any error messages that are generated by the Nyquist code.

To force the plug-in to create an interface, all that you need to do is to add a “control” in the header section. The control does not need to “do” anything, but if you include one then the effect will open with an interface.

The “controls” are described in the documentation as “widgets”. http://wiki.audacityteam.org/wiki/Nyquist_Plug-ins_Reference#Nyquist_Plug-in_Widgets

Here is an example of a slider widget added below the other plug-in header information:

;nyquist plug-in
;version 3
;type process
;name "Append Random Silence"
;info "by goldfinger35 nReleased under GPL v2.n"

;; Based on a code snippet by Steve.
;; Released under terms of the GNU General Public License version 2:
;; http://www.gnu.org/licenses/old-licenses/gpl-2.0.html

;control dummy "Dummy Slider" real "blah" 50 0 100

and this is what it looks like:
dummy.png
Now if you apply the effect using the “Debug” button, you should see a rather cryptic message that starts off with:

MULTISEQ's 2nd behavior: (S-REST SILENCE-DURATION)
error: arguments not compatible

Not very helpful for someone working on their first ever plug-in, but at least it gives a clue that the problem is a compatibility issue involving the “S-REST” function (and something to do with “MULTISEQ” :confused: )

The problem is that the SEQ function does not work with stereo sounds.
In our code, the following line tries to join “S” and our generated silence “(s-rest silence-duration)” in sequence,

 (seq s (s-rest silence-duration))

but “S” (the sound that is passed from Audacity to Nyquist) is not a “normal” sound - it is a stereo sound. Stereo sounds are handled as an “array” which contains two elements - the first element is the sound of the left channel and the second element is the sound of the right channel.

There is a section in the “Nyquist Plug-in Reference” that deals with stereo sounds: http://wiki.audacityteam.org/wiki/Nyquist_Plug-ins_Reference#Stereo_Tracks

I’m sure that you want to get on and use this as soon as possible, so here are two solutions the problem. The first is probably more easily understandable, but the second is a more flexible approach:

(setq silence-duration (+ 10 (random 41)))

;; generate silence
(setq my-silence
  (abs-env
    (s-rest silence-duration)))

(if (arrayp s)
    (vector (seq (aref s 0) my-silence)
            (seq (aref s 1) my-silence))
    (seq s my-silence))



(setq silence-duration (+ 10 (random 41)))

;; Sequence function
(defun sseq (sig1 sig2)
  (seq sig1 sig2))

(abs-env
  (let ((my-silence (s-rest silence-duration)))
    (multichan-expand #'sseq s my-silence)))