2

我正在尝试使用 Audacity 从音频文件中删除静音。有一个名为Trim Silence的 Nyquist 插件可以删除文件开头和结尾的静音,但不会删除中间的静音。我想反转这一点,并从除了开始和结束之外的所有地方删除沉默。

我认为下面的功能是插件的相关部分。我应该如何更改它以获得 truncate-internal-silences 功能?(我不知道任何 Nyquist 或 Lisp,所以我很难理解它目前的作用,更不用说改变它了。)

也欢迎完全不同的方法 - 这只是我目前对如何编辑我的许多音频文件的最佳猜测。

(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*)))))
4

0 回答 0