Deleting silence every second

I have a streamed audio track that looks like it was stretched by adding silence every 1000ms. The duration of the silence increments and then resets.

The duration goes:

0ms (no gap)
4ms
6ms
8ms
11ms
14ms
16ms
19ms

Then back to 0. The start of the gaps is exactly 1000ms apart.

The gap isn’t necessarily completely silent so I can’t use Truncate Silence to remove them. At the level required to catch them all it starts to delete good portions.
Since they are all 1000ms apart is seems like there should be a way to:
Advance 1000ms, select 4ms, delete
advance 996ms, select 6ms, delete
advance 994ms, select 8ms, delete
etc.

You could type the times into the Selection Toolbar: Selection Toolbar - Audacity Manual

There’s 3.5 hours of it. I’m looking for a way to avoid manually deleting 12000 segments.

Is there a pattern here?

What sort of solution are you looking for? I’m not sure what you’re asking.

That’s the pattern.

Every 1000ms a gap begins. The gap widens until it wraps back around to 0.
So I need a way to cut out 1000-1004, 2000-2006,3000-3008,4000-4011,5000-5014,6000-6016,7000-7019, skip 8000 (no gap/reset), 9000-9004… etc.

I think that would be possible with a “Nyquist Macro”, but before spending too much time on this, I’d suggest that you try doing a bit of it manually (using the Selection Toolbar to make the selections). Is the result satisfactory, or does it leave objectionable clicks every second?
I’d also suggest looking into the possibility of getting a recording that doesn’t have the problem - that could be a lot quicker, easier, and more effective than trying to create a plug-in to fix this badly damaged recording.

I did 10 minutes manually (taking a couple hours) and it sounds great.

There are two sources available and both have the same issue.

Please post a short sample of the audio so that I can see exactly what we are dealing with. About 20 seconds in WAV format would be good.
Did you make the original recording in WAV format?

The original is AAC.

Hmm… can’t attach a .mka or .aac.

Ok, I got sick of “file too large” errors and just renamed a mka to wav to get around the silly file extension requirements.

AAC is a lossy compressed format. Lossy compression produces an approximation of the original, with a much smaller file size. It’s possible that the original had absolute silence in those gaps, which would then mean that you could use Truncate Silence. Is it possible for you to re-record the original?

It is the only source which is why I’m trying to fix it.

OK, here’s a script that can do most of the job.

  1. First, you need to select the track starting exactly at a 0ms (no gap) point in the track, and extend the selection to the end of the track.
  2. There must be only one track in the project.
  3. Enter this code in the Nyquist Prompt, and apply it:
;version 4
;type tool

(setf start  (get '*selection* 'start))
(setf end  (get '*selection* 'end))
(setf durations (list 0 0.004 0.006 0.008 0.011 0.014 0.016 0.019))
(setf gaps (length durations))
(setf loops (truncate (- end start)))

(dotimes (i loops)
  (setf t0 (+ start i))
  (setf delta (nth (rem i gaps) durations))
  (setf t1 (+ t0 delta))
  (when (> delta 0)
    (aud-do (format nil "SelectTime: start=~a end=~a RelativeTo=\"ProjectStart\"~%" t0 t1))
    (aud-do "Silence:")))

(aud-do (format nil "SelectTime: start=~a end=~a RelativeTo=\"ProjectStart\"~%" start end))
(aud-do "TruncateSilence:Action=\"Truncate Detected Silence\" Minimum=0.003 Threshold=-80 Truncate=0")
"Done"

This is the result:

Thank you. I had to split it into 10 minute pieces and do them individually or otherwise Audacity would output nothing but a blank, but it worked.

That’s useful to know. I think there’s a limit to the number of commands that a Macro can do in one go. This code is running two Macro commands for every second of audio, plus one more to the entire selection, so that’s 1201 commands for a 10 minute selection.

Super :smiley:

No. That’s not the cause.

The problem was that the code was rounding decimal numbers as described here: XLISP *float-format*

The fix is to set *float-format" to use the %f specifier:

;version 4
;type tool

(setf *float-format* "%f")

(setf start  (get '*selection* 'start))
(setf end  (get '*selection* 'end))
(setf durations (list 0 0.004 0.006 0.008 0.011 0.014 0.016 0.019))
(setf gaps (length durations))
(setf loops (truncate (- end start)))

(dotimes (i loops)
  (setf t0 (+ start i))
  (setf delta (nth (rem i gaps) durations))
  (setf t1 (+ t0 delta))
  (when (> delta 0)
    (aud-do (format nil "SelectTime: start=~a end=~a RelativeTo=\"ProjectStart\"~%" t0 t1))
    (aud-do "Silence:")))

(aud-do (format nil "SelectTime: start=~a end=~a RelativeTo=\"ProjectStart\"~%" start end))
(aud-do "TruncateSilence:Action=\"Truncate Detected Silence\" Minimum=0.003 Threshold=-80 Truncate=0")
"Done"