Trim Silence

Trims silence from the start and the beginning of the selected audio.
The major difference between this effect and “Truncate Silence” is that this effect will never affect silences within the audio. It only acts on audio at the start and end of the selection.

After processing there may still be a few milliseconds of silence at the beginning/end, particularly on longer tracks (several minutes). This is by design to allow reasonable processing speed and to avoid trimming off non-silence. On short audio tracks (a few seconds) the trimming will be very close to the start of the audio (little or no silence will be left at the start /end of the selection).

This effect requires Audacity 1.3.8 or later.

This effect is supported in Chains in Audacity 2.0.1 and later.

As with other Nyquist effects it can be very slow and may cause Audacity to crash if used on very long selections (tracks of several hours or more duration).

OBSOLETE VERSIONS:

TrimSilence.ny (2.2 KB)
[/size]
TrimSilence.ny
Current version: http://wiki.audacityteam.org/wiki/Nyquist_Effect_Plug-ins#Trim_Silence

As with many other plug-ins, this effect may create a “split” in the track at the end of the processed selection. To remove this split, press Ctrl+J (Join).

I have some compact disc music albums that play seamlessly on cd players, with no gaps between one track and the next (eg one hour of continuous music by some orchestra or random dj). Unfortunately, when playing back these albums ripped to mp3, very short gaps (or “clicks”) can be heard on some mp3 players whilst it moves from one mp3 to the next. This can be annoying on albums with very short tracks, especially if one “song” can be made up of more than one track too. Ripped mp3s have a few milliseconds of silence by nature at the start (and possibly also end) of each file, and not all mp3 players can leave this out during playback either (especially portable java mobile players), I therefore wanted to remove the silence on each mp3, and finally combine all the tracks together, so that I could listen to the album on these players seamlessly. With 38 (!) previously ripped mp3 tracks from one album, I have now managed to remove the silence from each track using this plugin using its default settings. I remove the silence from one track, add a new track, remove the silence from that also, and then finally cut and paste it onto the end of the last, and so on. Very little editing was needed. On a few short occassions (after zooming in to almost fill the screen) some silence would still be present in the graphic after joining files together and removing the split, but it would usually sound seamless. If it didnt I just had to zoom in to remove the gap (to join the two files completely), then zoom out to check if it sounded ‘as one’. I believe that some of the silence still being present may have been down to audacity adding some whilst cutting and pasting one track onto the end of another. If that isnt possible, I simply could have played more with this plugins settings to be more accurate in its deletion of silence, but the plugin definately made a difference. In the end this has given me one single mp3 that plays with no obvious clicks/silence-perfect for my portable player. It didnt take as long as I thought it would either :mrgreen: but next time I might consider using a ripper that can rip my albums as one single mp3 :unamused: cheers

This version fixes a bug in which silence could be detected incorrectly in some stereo tracks.

Memory usage has also been reduced a little.
To prevent Audacity freezing or crashing if RAM becomes full, RAM usage is limited to (approx) 1 GB (about 47 minutes for a stereo track at 44.1 kHz)

Modification tip:
Users that have more physical RAM available and want to process longer files can increase the maximum size by following the instructions in the comments near the top of the plug-in code.
TrimSilence.ny (3.37 KB)

How can I modify your plugin to leave 1-2 seconds of silence at the end of each track?

To leave 2 seconds of the silence, find the part that says:

    (let ((start (/ (first result) my-srate))
          (end (- (get-duration 1)(/ (second result) my-srate))))
      ;; ensure at least 1 sample remains
      (if (>= start (get-duration 1))
        (setq start (/ (1- len) *sound-srate*)))
      ; trim
      (multichan-expand #'extract-abs start end (cue s))))

and change it to:

    (let ((start (/ (first result) my-srate))
          (end (- (get-duration 1)(/ (second result) my-srate))))
      ;; ensure at least 1 sample remains
      (if (>= start (get-duration 1))
        (setq start (/ (1- len) *sound-srate*)))
      ; add up to 2 seconds to end and trim
      (if (<= (+ end 2) (get-duration 1))
          (setq end (+ end 2))
          (setq end (get-duration 1)))
      (multichan-expand #'extract-abs start end (cue s))))

Thanks for your quick reply. Works great now.

Did you make this plugin, steve?

In any case, this plug-in is awesome. Some CDs have a few seconds of silence at the beginning and end of each track, which can be annoying. I use the plug-in in batch mode to trim the silence. Works like a charm!

For the record, there is a little tool called mp3directcut ( http://mpesch3.de1.cc/mp3dc.html ), which can losslessly auto-trim silence in MP3 and AAC files, that is, without recompressing them. So if you need to trim silence on already compressed files, this is the best way.

Yes, this is one of my efforts.
Thanks for the feedback - I’m glad you find it useful.

Yes, mp3directcut is a useful tool for trimming MP3s.
There is also Mp3splt which can split MP3s (an Ogg files) losslessly http://mp3splt.sourceforge.net

Hi Steve,

This is a great plugin, it’s work fine manually but I don’t add it in Chain script.
Maybe you can help doing it?
I have a hundreds of mp3 files to trim and convert to ogg. Doing it manually are killing me :slight_smile:
Thanks

How far have you got? What is the problem?

My problem is that the “Trim Silence” is not in the plugin list when I click “File” → “Edit Chain” → “Insert”.
It is possible to use it in Chain mode?
audacity.png

The first post in this topic says

This effect is supported in Chains in Audacity 2.0.1 and later.

You can get the latest Audacity 2.0.5 from here: Audacity ® | Downloads .


Gale

Thank you a lot. I don’t know why I have an oldversion of Audacity.
I installed the latest version and it’s works fine.

Hi,

Crashes if I try to run on 2-hour recording.

See crash:
AudacityTrimSilenceCrash.png
I set:

(setq RAM-Limit 3.0) ; RAM limit in GB

Audacity 2.0.6 on Windows 8.1 x64.

Crashes at the 17 second mark every time.

Thankfully easy enough to work around just by doing an hour at a time or less.

And plenty of RAM, 16GB. I monitored Audacity while processing and computer is only using 47.17% MAX.

Thanks,

Will

Although your computer may have more than 4 GB available, Nyquist is 32 bit and is therefore unable to address more than 4 gigabytes (4096 megabytes) of memory.
Due to limitations in the Audacity/Nyquist interface, many Nyquist effects (including this one) require the audio to loaded into ram. Regardless of the track format, the audio is processed in 32 bit float format, so even assuming there are no memory leaks, inefficiencies or other bugs, the maximum length of a 441100 Hz stereo track that can be handled by this effect must be less than (about) 1.7 hours. This may be improved in future generations of Nyquist plugins if Nyquist gains the ability to directly address audio samples from Audacity without loading the entire sound into ram.

Being that this effect removes silence from the start/end of the selection, if your track has say about 5 seconds of silence at each end, you only need to apply the effect to a little more than 5 seconds at each end.

So that’s addressing a 2 GB limitation in a 44100 Hz stereo track?

That would make sense to me because on Windows, 32-bit applications have 4 GB of virtual address space available, but divided so that 2 GB is available to the application and the other 2 GB available only to the system. 3 GB can be made available to the application with IMAGE_FILE_LARGE_ADDRESS_AWARE and 4-Gigabyte Tuning.


Gale

Understood. Makes perfect sense…

Too bad it crashes, instead of just an error and/or warning to the user about the limitation.

The version that I have gives an error:
Error.
Max RAM usage by Trim Silence is set to 1 GB.
This allows a maximum duration for a mono
track at 44100 Hz of 1h:34m:29s.
Selected track is 12h:0m:10s.