Silence Lengthen Not Working as Expected

I found a plugin from this post, briefly, it finds all silence sections and insert some extra silence into them. And I tried to add another option sil-dur-max for detecting silence, it runs, but does nothing except for returning a message Nyquist returned a list. How can I make it work? I’m using Audacity 3.5.1.

By the way, how to truncate the silence sections, instead of inserting?

;nyquist plug-in
;version 1
;type process
;categories "http://lv2plug.in/ns/lv2core#AnalyserPlugin"
;name "Silence Lengthen"
;action "Inserting silence..."
;info "Based on Silence Finder by Alex S. Brown\n\Released under terms of the GNU General Public License version 2\nHacked by Steve Daulton as a 'proof of concept'.\n\n"

;control sil-lev "Treat audio below this level as silence [ -dB]" real "" 26 0 100
;control sil-dur-min "Minimum duration of silence [seconds]" real "" 1.0 0.1 5.0
;control sil-dur-max "Maximum duration of silence [seconds]" real "" 1.0 0.1 5.0
;control slen "Length of Silence to Insert" real "[seconds]" 1 0.1 30

(setq labelbeforedur (/ sil-dur-min 2.0))

;Create a function to make the sum the two channels if they are stereo
(defun mono-s (s-in) (if (arrayp s-in) (snd-add (aref s-in 0) (aref s-in 1))
s-in))

;Create a function to reduce the sample rate and prepare the signal for
;analysis. RMS is good to monitor volume the way humans hear it, but is not
;available in Audacity. Used a peak-calculating function instead.
;NOTE: this is the place to add any processing to improve the quality of the
;signal. Noise filters could improve the quality of matches for noisy signals.
;PERFORMANCE vs. ACCURACY
;Reducing the samples per second should improve the performance and decrease
;the accuracy of the labels. Increasing the samples per second will do the
;opposite. The more samples checked, the longer it takes. The more samples
;checked, the more precisely the program can place the silence labels.
;my-srate-ratio determines the number of samples in my-s. Set the number after (snd-srate s)
;higher to increase the number of samples.

(defun my-s (s-in)
 (setq my-srate-ratio (truncate (/ (snd-srate (mono-s s-in)) 100)))
 (snd-avg (mono-s s-in) my-srate-ratio my-srate-ratio OP-PEAK)
)

;Set the silence threshold level (convert it to a linear form)
(setq thres (db-to-linear (* -1 sil-lev)))
;Store the sample rate of the sound
(setq s1-srate (snd-srate (my-s s)))
;Initialize the variable that will hold the length of the sound.
;Do not calculate it now with snd-length, because it would waste memory.
;We will calculate it later.
(setq s1-length 0)
;Initialize the silence counter and the labels variable
(setq sil-c 0)
(setq l NIL)
;Convert the silence duration in seconds to a length in samples
(setq sil-length-min (* sil-dur-min s1-srate))
(setq sil-length-max (* sil-dur-max s1-srate))

;Define a function to add new items to the list of labels
(defun add-label (l-time l-text)
 (setq l (cons (list l-time l-text) l))
)

;The main working part of the program, it counts
;the number of sequential samples with volume under
;the threshold. It adds to a list of markers ever time
;there is a longer period of silence than the silence
;duration amount.

;It runs through a loop, adding to the list of markers (l)
;each time it finds silence.
(let (s1) ;Define s1 as a local variable to allow efficient memory use
 ; Get the sample into s1, then free s to save memory
 (setq s1 (my-s s))
 
 ;Capture the result of this "do" loop, because we need the sountd's legnth
 ;in samples.
 (setq s1-length
  ;Keep repeating, incrementing the counter and getting another sample
  ;each time through the loop.
  (do ((n 1 (+ n 1)) (v (snd-fetch s1) (setq v (snd-fetch s1))))
   ;Exit when we run out of samples (v is nil) and return the number of
   ;samples processed (n)
   ((not v) n)
   ;Start the execution part of the do loop
   ;if found silence, increment the silence counter
   (if (< v thres) (setq sil-c (+ sil-c 1)))

   ;If this sample is NOT silent and the previous samples were silent
   ;then mark the passage.
   (if (and (> v thres) (>= sil-c sil-length-min) (<= sil-c sil-length-max))
 	  ;Mark the user-set number of seconds BEFORE this point to avoid clipping the start
 	  ;of the material.
    (add-label (- (/ n s1-srate) labelbeforedur) "S")
   )
   ;If this sample is NOT silent, then reset the silence counter
   (if (> v thres)
    (setq sil-c 0)
   )
  )
 )
)

;Check for a long period of silence at the end
;of the sample. If so, then mark it.
(if (>= sil-c sil-length-min)
 ;If found, add a label
 ;Label time is the time the silence began plus the silence duration target
 ;amount. We calculate the time the silence began as the end-time minus the
 ;final value of the silence counter
 (add-label (+ (/ (- s1-length sil-c) s1-srate) sil-dur-min) "S")
)

;If no silence markers were found, return a message
(if (null l)
 (setq l "No silences found. Try reducing the silence\nlevel and minimum silence duration")
)
(setf insert (list (get-duration 1)))
(dotimes (times (length L))
(setf insert (push (car (nth times L)) insert)))
(setq insert (push 0.0 insert))

(setq slist (list (extract-abs (nth 0 insert)(nth 1 insert) s)(extract-abs (nth 1 insert)(nth 2 insert) s)))

(setf slist ())
(setq seg (1- (length insert))) ; number of segments

(dotimes (var seg)
   (setf slist (push (extract-abs (nth (- seg (1+ var)) insert)(nth (- seg var) insert) s) slist)))

(seqrep (var seg)
   (seq
      (cue (nth var slist))
      (cue (stretch-abs 1.0 (s-rest slen)))))

OK, I found the stereo version. Now the only question remaining is how to truncate silence instead of inserting?

The code you are using is ancient - one of my early attempts at modifying Nyquist code. There is a later version here: Extend Silences

Thank you! Is there a way to truncate silence instead of inserting?

You will probably need Nyquist’s EXTRACT function.