Processing long tracks with DeClicker.ny

Hi, something like this could be very useful for me - I’m very new to Audacity macros, by the way.

I have a filter that I want to run on the whole of a single track in an Audacity file, it can be maybe 40 to 70 minutes long, varies each time. The filter is very intensive, and it fails (crashes no work done) if the time length is too long. It does work if I select a shorter time span, so I can do it in bits, but that’s obviously a pain.

I would like to do a macro to run this macro on successive sections of the track, say from timecode 0 to 10 minutes, 10 minutes to 20 minutes, and so on to complete the track. The thing is that I don’t know how long the track will be each time, so I might be selecting from 50 to 60 minutes of a track that only lasts 45 minutes, or might last 71 minutes, so I don’t know how to end my cycle running it on chunks of the track.

Another option might be to run the filter from 0 to [total time/5], then from [total time/5] to [total time/5*2], and so on, but I can’t find any syntax to do that.

All suggestions very welcome, thanks in advance!

What’s the filter? Depending on why the filter is crashing, your suggested workaround may or may not work. Of course the best solution would be to fix the “filter” (if that is possible).

The filter is DeClicker.ny. It works fine on shorter chunks of audio, but takes about 12 seconds per minute of audio to run, so I presume long audio clips just make it fall over.

Yes, it would be good to fix that but nevertheless it would be good to work out how to programatically select dynamic sections of a track.

Are you using the latest version of DeClicker? (this one: Updated De-Clicker and new De-esser for speech)
What settings are you using?

It works for me with a:

  • 1 hour mono track
  • sample rate of 44100
  • default settings in DeClicker

What do I need to do to make it fail?

The post that you linked is from 2014, is there a link deeper into the thread to a later version?

  • I’m processing a track that is 49 minutes
  • 44.1k
  • one of two tracks in a wav file that I have imported into Audacity (originally recorded using Voicemeeter)
  • It has previously had filters Noise Reduction, Change pitch, de-esser run on it
  • De-clicker default settings running
  • It starts off with a remaining time of about 5 minutes
  • The remaining time ticks down more slowly than the elapsed time ticks up
  • When it says about elapsed 3.05 and remaining 3.45, the dialog with the fill bar disappears, there is no error message, and the track has not been edited and the De-Clicker is not visible in the Undo option, the previous action is.

The most recent version is in the first post of that thread. Yes it’s old.

OK, I can reproduce the problem with a 1 hour stereo track.
Debugging the issue shows the cause of the problem:

The maximum number of sample blocks has been
reached, so audio computation must be terminated.
Probably, your program should not be retaining
so many samples in memory.

I think it’s highly unlikely that the plug-in developer will fix the issue, and the code is absolutely horrible so I have no intention of fixing it for him. As a workaround, you could try this macro:
DeClick_5_audio_clips.txt (1.62 KB)
To use the macro, first split the track into 5 clips (add 4 “split lines” at roughly equal intervals: https://manual.audacityteam.org/man/edit_menu_clip_boundaries.html)
Then run the macro.
Then wait … and wait … and wait … and wait … and wait …

(I’m assuming that it will work, but I’m still waiting for it to complete)

I’ll give that a go, many thanks!

My original idea was to process it in n regions by programatically selecting the first 1/n of the track, then the second and so on, and processing each separately. Is there any way to select like that in a macro?

Running it now and it’s gone through three chunks, but it’s still the first chunk that appears selected, is that just a visual effect?

There’s no easy way of doing that. It is “possible”, but you would need to write two Nyquist scripts (see Nyquist - Audacity Manual), one to analyse the track and work out the times of the selections, and another to make the selections, then incorporate those two scripts into the macro.

It could be. Audacity prioritises the audio processing over updating the waveform. The waveform should be fully updated once the macro has completed.
My test is now on the final clip so I’ll be able to say if it has worked here in a couple of minutes.

It took a long time, but it got there in the end and completed successfully.

I imported and tested the macro you uploaded, it is definately doing the operation 5 times on the first clip, and not on any of the others. I tested it by changing the code to this:

CursTrackStart:
SelNextClip:
De-clicker:control-action-choice="Apply changes" control-crackle-threshold="-45" control-crossfade-interval="5" control-frequency-bound1="150" control-frequency-bound2="9600" control-max-steps="2" control-n-bands="12" control-passes="2" control-relative-threshold="6" control-separation="3" control-step-dur-ms="5"
SelNextClip:
Amplify:Ratio="0.31622777"
SelNextClip:
De-clicker:control-action-choice="Apply changes" control-crackle-threshold="-45" control-crossfade-interval="5" control-frequency-bound1="150" control-frequency-bound2="9600" control-max-steps="2" control-n-bands="12" control-passes="2" control-relative-threshold="6" control-separation="3" control-step-dur-ms="5"
SelNextClip:
Amplify:Ratio="0.31622777"
SelNextClip:
De-clicker:control-action-choice="Apply changes" control-crackle-threshold="-45" control-crossfade-interval="5" control-frequency-bound1="150" control-frequency-bound2="9600" control-max-steps="2" control-n-bands="12" control-passes="2" control-relative-threshold="6" control-separation="3" control-step-dur-ms="5"

And this is the result that I got:

All help gratefully welcomed!

You will need to update Audacity. I’ve just tested with Audacity 3.2.0 and I can reproduce the problem.
I’ve also tested with Audacity 3.2.2 and it works correctly.

Here’s a fast version of the macro script for testing. It applies a “fade out” to each of the 5 audio clips:
quick-test.txt (281 Bytes)

Thanks for all your dedication. I’m on version 3.2.3 and the quick test is happening to the same first clip 5 times, giving an error each time that says, “Fade Out: Could not load settings below. Default settings will be used”.

I’m on Windows 11 if that is relevant.

This is weird. I thought that it was just a problem in an old version, but on further testing I’m getting inconsistent results regardless of the version. Sometimes it works and sometimes it doesn’t, but I don’t see any pattern as to why it works sometimes but not others.

After testing with multiple versions, the only version I have that it’s working reliably and consistently with is Audacity 2.4.2 (the version that I use for production work).

I’ll need to do more testing tomorrow, but it’s looking like a “race condition” bug in multiple versions of Audacity.

I’ve logged it as a bug: https://github.com/audacity/audacity/issues/4146

I’m not sure what more I can suggest. Audacity is failing to process the macro correctly, which is a regression against much older versions. It bothers me greatly that Audacity has become unreliable when processing macros.

Thanks for all your work on this Steve…

If you or anyone else can suggest a way to select a dynamic way to select a portion of the track (say the total length/n) rather than a fixed value, I would be happy to work with that.

If your “filter” was a built-in effect or any type of plug-in other than a Nyquist plug-in, then this would be simple to do in Nyquist with something like this:
(You can try running this code in the Nyquist Prompt - see: Nyquist Prompt - Audacity Manual)

;type tool
;control num "Number of sections" int "" 5 2 20

(defun start-end ()
   (let ((tracks (aud-get-info "tracks"))
         start end)
      (dolist (trk tracks)
         (when (= (second (assoc 'focused trk)) 1)
            (return-from start-end
               (list (second (assoc 'start trk))
                     (second (assoc 'end trk))))))))

(defun fade (t0 t1)
   (aud-do-command "select" :start t0 :end t1)
   (aud-do "FadeIn"))

(let ((ends (start-end)))
   (setf start (float (first ends)))
   (setf end (float (second ends)))
   (setf step (/ (- end start) num))
   ;first section
   (fade start (+ start step))
   (setf start (+ start step))
   ;middle sections
   (dotimes (i (- num 2))
      (fade start (+ start step))
      (setf start (+ start step)))
   ; final section
   (fade start end)
   "")

Unfortunately this can’t work with DeClicker.ny because a Nyquist script cannot call a Nyquist plug-in, but if this works reliably for you, then it can be adapted as I suggested in this post: Processing long tracks with DeClicker.ny - #10 by steve and I can help you to do that.

Many thanks again Steve, I’ll have a go at this.