Shorten Silences during playback of an audio stream/file on iOS

iOS Apps like Overcast, Pocket Casts, and couple others I've read about, have the ability to skip/trim silent moments as they play back/stream audio. This is often used to remove/shorten long pauses (in voice content) to save time when listening.


I think I understand the high-level concept, but I'm not sure where in the audio pipeline would be best to implement the ability to skip/trim/shorten silences.


There's a few iOS audio streaming frameworks that give access to the audio stream bytes and/or samples (ie. using AudioUnits, AudioFileStreamOpen, etc.


However, I'm not sure how/when to modify the buffer to remove or shorten silence.


From what I understand, a couple options would be to:

1) Remove samples from the audiobuffer (that are under a certain amplitude threshold and deemed "silence") thus altering the buffer length.

2) Not remove samples, but seek to the next non-silent moment (as if moving the seek time forward).


In either instance, I'm not sure what the best way to approach this or if either solution is right. The app Audacity has some code that takes an audio file in and truncates the silence (shortens or compresses it proportionally) and ramps the fade in/out so not to introduce any artifacts. The code is here, but I'm not sure if it's useful for this purpose (since it's not happening during playback) or how I'd integrate it. https://github.com/transformersprimeabcxyz/auda2015/blob/1fa66fa8f3906bebd1e04b4a88d9da469fa82033/audacity-src/tags/Audacity_1_3_9/audacity-src/src/effects/TruncSilence.cpp


Any ideas or code on how to approach this?