I have found the TrimSilence plugin, which truncates silence only at the beginning and end of an audio file, and not in the middle.
I would like to do the inverse: truncate silence only in the middle of a file, not at the edges.
I’ve never coded Nyquist or anything like it; can anyone help me edit the plugin?
I believe this is the relevant function:
(defun trim-silence () ;; Nyquist plug-ins cannot return 'no audio', so trap as error. (if (< (get '*selection* 'peak-level) threshold) (throw 'error (format nil "Error.~%All selected audio in the ~a selected track~%~ is below the silence threshold.~%~%~ Try setting the threshold to a~%~ lower (more negative) dB level." (add-num-suffix (get '*track* 'index))))) (if (> len (* limit *sound-srate*)) ;max length in samples (throw 'error (format nil "Error.\nMax RAM usage by Trim Silence is set to ~a GB.~%This allows a maximum duration ~ for a ~a~%track at ~a Hz of ~a.~%Selected track is ~a.~%" RAM-limit (if (arrayp *track*) "stereo" "mono") (round *sound-srate*) (to-hhmmss limit) (to-hhmmss (get-duration 1))))) (let* (;; ratio provides tighter trimming for short selections ;; while maintaining reasonable speed for long selections (ratio (max 10 (min 200 (round (/ len 100000.0))))) (my-srate (/ *sound-srate* ratio)) (mysound (convert *track* ratio)) (limits (get-clip-limits)) ; (list start, end) times of audio clips (clip-start (if (first limits) (abs-to-relative-time (nth 0 limits)))) ; nil id invalid (clip-end (if (second limits) (abs-to-relative-time (nth 1 limits))))) ; nil if invalid ;loop through samples and mark start and end (setf result (find-sil mysound clip-start clip-end)) (let ((start (if clip-start (max clip-start (- (/ (first result) my-srate) min-start-silence)) 0)) (end (if clip-end (min (+ (- (get-duration 1) (/ (second result) my-srate)) min-end-silence) clip-end) (get '*selection* 'end)))) ;; ensure at least 1 sample remains ;; This should never happen. (if (>= start end) (setq start (- end (/ *sound-srate*)))) ; trim (multichan-expand #'extract-abs start end (cue *track*)))))