Adding random silence to multiple mp3 files?


I have around 100 mp3 files and I want to add a random silence (between 10 and 50 seconds) to the end of each mp3 file.
Is it possible in Audacity 2.0.3?


BTW, I know how to add it manually 1 by 1 but it takes forever to finish. Is there to any way to add it all at once.

Yes it’s possible, but note that there is always some sound quality loss when editing MP3s because Audacity needs to decode the MP3 in order to edit it, then if you need the edited version in MP3 format, exporting in MP3 format will re-encode it. Encoding to MP3 format always loses some sound quality.

I presume that you want to automate the process as much as possible? In which case you would need to write a Nyquist script that can run as a plug-in in a Chain.
“Chains” provide the mechanism in Audacity for “batch processing” multiple files.

See these two links for information about Chains:

Adding a random amount of silence to the end of a file is an unusual task, so not surprisingly there is no built-in command for this. However, Audacity includes a “scripting language” called “Nyquist” that allows users to write plug-in effects that can do just about anything :wink:
There is an introduction to writing Nyquist plug-ins here:

If you are interested in writing a plug-in to add silence to the end of a file, then it is a relatively simple task and we can help you with that. If it sounds like more trouble than it’s worth, then the manual method would be:

  1. Import a file
  2. Zoom out so that you can see roughly where you want the added silence to end.
  3. Select about a second of empty space in the track where you want the silence to end
  4. Generate > Silence
  5. Export (Highly recommended that you export to a new folder so that you don’t overwrite the original file).
  6. Repeat steps 1 to 5 for each file.

[Update] Your second post arrived while I was typing.

The Nyquist code that you need would be something like this:

(setq silence-duration (+ 10 (random 41)))
  (seq s (s-rest silence-duration)))

So then you just need to add a plug-in header to make it into an Effect (process) type plug-in.
This will add a random number between 10 and 50 of whole seconds of silence.
If you don’t want the added silence to always be whole seconds, then you would need to change (random 41) to something like ( 40 (rrandom))*

For partial seconds you can also write:

(setq silence-duration (real-random 10.0 50.0))

Ok. I have tested it and it works great - easy and simple but I couldn’t have done it without your help. Thank you very much!

I have another (unusual?) question so any help would be appreciated:
I have 100 mp3 files and I want to add fade in effect (2-3 seconds) to the beginning of the each file and fade out (2-3 seconds) to the end of each file. I know how to do it one-by-one but is there a way to automate the process (in Nyquist?) Thank you.

You’re welcome.
We have a little tradition on this forum - it’s not compulsory, but it’s a nice tradition: When someone comes up with a Nyquist plug-in that works with the help of other forum users, they “publish” (post) the finished plug-in to the New Plug-ins section of the forum, licensed as GPL v2, so that other people in the Audacity community can benefit.

If you wish to mark it as licensed under GPL v2, just add “Released under GPL v2.” in the “info” header line, and add “Released under terms of the GNU General Public License version 2:” as a comment. An example, here is the header of the “Sample Data Export” plug-in:

;nyquist plug-in
;version 3
;type analyze
;name "Sample Data Export..."
;action "Analyzing..."
;categories ""
;info "by Steve Daulton. Released under GPL v2." 

;; sample-data-export.ny by Steve Daulton June 2012.
;; Updated July 16 2012.
;; Released under terms of the GNU General Public License version 2:
;; For information about writing and modifying Nyquist plug-ins:

I’m pretty sure there is already a plug-in that can do that - I’ll see if I can find it.

[:Update:] Here it is:
This is a very old plug-in, so the style of coding is not particularly good. There are also lots of unnecessary empty lines (David Sky, the author of this plug-in, was blind, so he probably wouldn’t have known that). Nevertheless it does what it says. Perhaps you’d like to have a go at updating this plug-in?

Thank you for the help. I have encountered a problem: above mentioned code for adding silence works only on mono tracks; for stereo it has no effect.

David Skys plugin works ok, but if it is applied to multiple files with different length, it only applies fade out effect to the longest one. I’ll test some more and update the plugin if I find a working solution.

Let’s deal with that in your “new plug-ins” topic:

If you don’t find a good solution, please start a new topic in the Nyquist forum:
If you do find a good solution, please start a new topic in the Nyquist forum anyway :smiley: (your solution could be useful for other users). We like to keep to one forum topic per question as it makes it much easier to find information in the forum.