Removing parts of an audio clip containing silence (Strip Silence)
Hello. Is it possible to make a device that removes parts of an audio clip containing silence?
I think need to load the audio into buffer~ --> peek~ find indexes below the volume threshold...
Also how can I get the index intervals between silence and signal something like: Signal -- Silence_A -- Silence_B -- Signal, where Silence_A is the entry point into silence and Silence_B is the exit point before a new signal appears and so on in a circle until the clip ends?
you need to incorporate 'hysteresis' into your detection:
once it falls below threshold, wait for a certain time before it can set a marker as the 'startSilence' marker(the timing is up to you, but you could start with trying something like 20ms of silence needed minimum). if the threshold goes back up before this time is up, then it's not truly a silence you want but just an abrupt change towards being below threshold.
if it satisfies the hysteresis condition, then you can mark that as a 'StartOfSilence' marker, then once it goes back above threshold after that, you can mark that index as a 'EndOfSilence' marker('Start...' and 'End...' can be variables in gen codebox, or stored within coll, etc.)... you don't need hysteresis for the 'End' since it should be following a significant amount of silence.
following that, you need to fade-out slightly before 'StartOfSilence' index, and fade-back-in slightly after 'EndOfSilence' index, and then you can cut the audio in between the fades by copying the audio starting at the fade-back-in point, all the way to the end of the buffer~, and paste that back right at the 'StartOfSilence' index.
then... rinse and repeat, rinse and repeat... until all silences are copied over :)
the process i described above is something i did within a Max-based tool i created, while working 2 years as full-time audio-ad producer at Pandora, because they had me on a very basic job cutting slates(the ID that comes before the ad, which is also followed by silence to be cut...) from client-ads, in between producing in-house ads. it was a shit job where i got badly exploited by the company, same as every other corporate american crap audio job i've ever worked :(
therefore, i don't like to think too hard about this type of thing, and i definitely won't remember what i did, but i'll upload the tool i made and perhaps looking at the C file here can help with a more advanced form(i believe i used RMS to detect things more reliably with hysteresis... but i don't want to explain the code... if it helps it helps, otherwise, ignore it)
___________________
there are probably much more efficient variations on what i described above(as in the way you detect, store variable/marker of index, and copy/cut... perhaps, you don't want to fade after End-Of-Silence if that might adjust a transient/attack to a kick-drum,etc... in which case, you can fade-in sooner and record a slightly different kind of index for the copy/cut-point(s)... but the general gist is the same: utilize hysteresis to detect the start, fade-out, detect the end, fade-back-in, cut/copy)... might even be more efficient in terms of speed to mark all silences and then do the multiple cuts/copies all in one go by utilizing an extra buffer... the extra buffer can help with resizing for the new total length, at the end, too.
i'm unable to think clearly on this(it's a depressing memory for me :( ...funny, how an algorithm can carry a feeling after you've been exploited to produce it)...but hopefully the general idea helps, and others might have better solutions or perhaps [mxj buf.Op] patches or similar that could help.
__________________
F--K Pandora radio! 😤
[Edit: @Cycling74, feel free to edit my post or ban me if the above goes against rules 😋🔫]
You will have hard time making this work, even that it is possible
why not use dedicated sample editor to batch process files you need to use ?

here max detected audio portions would need to be copied (including fades)
to another buffer ...

Source Audio, Do you use a separate application to detect silence and export audio portions/indexes?
First screen shot is Audio Editor TwistedWave,
which like quite few other editors has option to detect and remove silences.
That short video at the bottom outputs detected audio portion
positions from coll.
I used custom external to get audio / silence indexes.
P.S
you asked for something that removes silent parts from audio file.
not something that exports individual slices without silent parts.
Source Audio, you talked about a custom external to get audio / silence indexes, is it available for download?
el.buffet~ check events
but ... be warned, some functions make max patch unusable.
I have modified version of it for personal use only, which uses samples insead of ms
for most functions.
Source Audio, this externals only for mac?
you can download from here latest version which includes windows externals.
P.S.
I am afraid that package is left in chaotic state.
on first link, windows externals are missing, on github release
at least external of interest - el.buffet~, misses functions
which should be there, for example :
1 events
2 pevents
3 catbuf
compiled version does not match latest source code ...
I have extracted some functions from it, compiled mac version for personal use
which works properly.
But I am afraid, you will have no luck with windows version,
at least not to get slices of audio/silence parts.
Are you still interested in this ?
I am thinking about installing visual studio and compiling my version for windows.
Source Audio, yes, that would be great! Perhaps in the future this will also be useful to someone! Thank you!
ok, I will let you know when I manage to make it.
Source Audio, By the way, how do you visualize the segments in this image? What is this object that displays indexes?

that´s the "selection" of the waveform~.
apropos visualisation. if you are using a control signal to do further processing on a sample, it is always a great idea to also display this control signal next to the sample, and if it is only for debugging your code (in this case noisegate or whatever you use.)
coll contains start/end points of detected audio regions.
they are sent to waveform to display them.
The idea is to select audio portions, create fades and export as individual
audio files, or then glue all in another file.
one can aso select only silence if one wants.
main thing is to get regions.