I found an apparently similar topic in Is it possible to create audio map of volume? but from the post 11 onwards it seems that data is returned to a list, which with the debug
option could be written to a file.
However, I need a band (say, of 300ms) of lowest amplitude peak range (assuming that the baseline zero RMS for my purpose is -33 dB, but it could be changed) to be selected on the very audacity waveform window itself for an already opened audio file.
I tried:
;; Define function to convert dB to linear scale
(defun db-to-linear (db)
(exp (* 0.11512925464970229 db)));; Set parameters
(setq base-threshold -33) ; Base RMS threshold in dB
(setq min-band-duration 0.3) ; Minimum RMS band duration in seconds;; Calculate linear-scale threshold from dB
(setq threshold (db-to-linear base-threshold));; Calculate Nyquist step size
(setq step (truncate (* min-band-duration sound-srate)));; Get RMS values for each segment
(setq rms-values (snd-avg track step step op-rms));; Find segments above threshold
(setq segments ())
(do ((rms (snd-fetch rms-values) (snd-fetch rms-values))
(start 0 (+ start step)))
((not rms))
(if (> rms threshold)
(setq segments (cons (list start (+ start min-band-duration)) segments))));; Find segment with minimum duration above threshold
(setq min-segment (car (sort segments #ā< :key #ā(lambda (x) (- (cadr x) (car x))))));; Convert segment start and end time to hour, minute, second, millisecond format
(setq start-time (format nil ā~2,'0d:~2,'0d:~2,'0d.~3,'0dā
(truncate (/ (car min-segment) 3600))
(truncate (mod (/ (car min-segment) 60) 60))
(truncate (mod (/ (car min-segment) 60) 60))
(truncate (* (mod (car min-segment) 1) 1000))))
(setq end-time (format nil ā~2,'0d:~2,'0d:~2,'0d.~3,'0dā
(truncate (/ (cadr min-segment) 3600))
(truncate (mod (/ (cadr min-segment) 60) 60))
(truncate (mod (/ (cadr min-segment) 60) 60))
(truncate (* (mod (cadr min-segment) 1) 1000))));; Output the selected segment
(format nil āSelected segment: ~a - ~aā start-time end-time)
Leaders and senior members may please note that this is a children level code and doesnāt work as intended. I have very fuzzy idea of accessing the native audacity script framework using the Nyquist Prompt.
I also would like to have the active window automatically be shifted to have the selected band centred within that window.