Extend Silences

Topic split from https://forum.audacityteam.org/t/modified-silence-marker-to-insert-more-silence/29449/1

This plug-in was originally developed in response to a request for a way to “stretch” the pauses in a language tutorial recording so that the user has more time to repeat each phrase. The plug-in is not restricted to speech recordings - it may be used in any type of recording where there is a need to extend the silences within the recording.

The plug-in code has copious in-line comments that describe how the plug-in works.
To view the code, open the plug-in file (“ExtendSilence.ny”) in a plain text editor (such as NotePad or the excellent NotePad++). For more information about Nyquist code, see: https://forum.audacityteam.org/t/manuals-and-reference-material/32817/1

How it works:
The plug-in scans the selected track, looking for places where the audio level remains below a specified level (the “Threshold”) for more than a specified period. These places are classified as “silences”. The plug-in then extends each detected “silence” by inserting additional silence at the end of each detected silence.

The amount of silence inserted may be defined in three ways:

  1. As an absolute length (in seconds).
  2. As a proportion of the length of the detected silence.
  3. As a proportion of the length of the preceding sound.

Any of these three methods may be used used at the same time.

For example, for a language tutorial CD, you may want to extend each “pause” by 50% of the length of the preceding phrase, plus 2 seconds. The resulting silence will then be:
{the length of the detected silence} + {50% of the length of the preceding phrase} + {2 seconds}


Controls:

  1. Threshold for silence (dB): [-100 to 0 dB. (default = -40 dB)]
    The peak level needs to drop below this level to be counted as “silence”. If there is background noise, the threshold will need to be raised to a higher (less negative) level.
  2. Min detected silence (seconds): [0.1 to 10.1 seconds. (default = 1.0 seconds)]
    If the audio remains below the Threshold level for at least this length of time, it will be classed as “silence”. Set to a smaller number if you wish to extend short gaps, or to a larger number if you wish to extend only long silences.
    Values greater than 10 seconds (up to 100 seconds) may be entered by typing into the text box.
  3. Add silence duration (seconds) [0 to 10 seconds (default = 5.0 seconds)]
    This extends each detected silence by the specified amount.
    Values greater than 10 seconds (up to 100 seconds) may be entered by typing into the text box.
  4. Add % of detected silence duration: [0 to 100 % (default = 0 %)]
    This extends each detected silence by an amount equal to a specified percentage of the detected silence. For example, if the detected silence is 10 seconds duration and this control is set to 50%, then 5 seconds of silence will be added.
    Values greater than 100 % (up to 1000 %) may be entered by typing into the text box.
  5. Add % of previous sound duration: [0 to 100 % (default = 0 %)]
    This extends each detected silence by an amount equal to a percentage of the duration of the preceding sound. For example, if there is a sound of 10 seconds duration before the detected silence, and this control is set to 50 %, then 5 seconds of silence will be added.
    Note leading silence before the first sound will not be extended by this control because there is no preceding sound.
    Values greater than 100 % (up to 1000 %) may be entered by typing into the text box.

The plug-in:
ExtendSilence.ny (5.11 KB)
Installation instructions: http://wiki.audacityteam.org/wiki/Download_Nyquist_Plug-ins#Installing_Plug-ins

Feedback and comments from plug-in users are an essential part of developing useful plug-ins.
For feedback, comments or questions, please post a reply to this topic.

I am also using this for language learning and this is almost exactly the plugin I need.

Is there a way it can be modified to have the option to add the silence to the End or Beginning of the track automatically? (instead of inserting it where silence already is)

Reason is, I have each sentence as 1 track, and I am trying to create 2 other versions - One with silence after (for repeating), and one with silence before (to say the sentence before the ‘answer’)

But with such short tracks, and sometimes not perfect recordings, it is not about extending silence, but just adding the right durations of silence, either to the beginning or the end.

Another, less important option (for me at least), question: what about reducing silence to the correct duration? for instance, for a track with several sentences, but too much silence in between several phrases. Is there a way to put in just the right amount of silence, reducing if necessary, and adding if necessary?

Something like this plugin, but the option to also add the silence at the beginning.

https://forum.audacityteam.org/t/pauken-add-silence-and-repeat-chunk/29659/1

Also, is there a way to bulk add an effect like this to each track individually instead of summing everything together, or having to repeat the effect for each track separately?

See “Trim / Extend” Missing features - Audacity Support

Unfortunately “Nyquist plug-ins” cannot tell the difference between empty track space (“white space”) and “silence”. They are also not able to see where audio clips start/end. Nyquist plug-ins can therefore not be reliably used for processes where the start/end of audio clips need to be considered. Rather, Nyquist plug-ins can only act on the current “selection”. However, please see this section in the manual about batch processing: Audacity Manual

Thanks. I have used the trim/extend plugin, but what I am going for is the ability to modify the amount of silence added relative to the selection/length of the audio or track.

If that makes sense.

Split from https://forum.audacityteam.org/t/easy-way-to-add-silence/35483/1

Well, it does work but not perfectly.
I was able to extend the silences in the program to meet the minimum.
But what I noted there was a “thump” that hit about -30db when the additional time was added.
You couldn’t hear it but it bumped the VU meters. The timer and time remaining don’t work.
When the timer ran out it just sat for a couple minutes before it completed.

So overall, it works but needs some fine tuning.

Thanks guys.

Thanks for the feedback.
The “thump” is probably due to the sudden change between low level noise in the “silence” that you are extending and the “absolute silence” that is inserted by the effect.
That is quite a tricky “problem” to address automatically because different use cases will probably require different approaches. One method would be for the effect to add a short fade-out to the original audio before inserting the silence and a short fade-in when returning to the original audio. Another approach would be to insert low level noise rather than absolute silence. There are probably other approaches too, but I can’t think of a general method that will suit all applications. The “best approach” is to use the effect on audio where the gaps to be extended are already “silent” (very low level) - for audio where that is not possible, use of a noise gate prior to inserting the silences may help.

…inserting additional silence > at the end > of each detected silence…

Hi Steve! Your plugin is amazingly useful! But it cuts some nearly quiet beginnigs of words. Could you add an option to choose where silences to insert: at begins, MIDDLES or ends of detected silences?! Thank you!

Try reducing the “Threshold” setting (a more negative number).

where silences to insert: at begins, > MIDDLES > or ends of detected silences

To cut them into silence pieces at any % as wanted, I just replaced:

  1. That line:
;control add-snd-pc "Add % of previous sound duration" real "" 0 0 100

by this:

;control add-snd-pc "Add % of previous sound duration" real "" 0 0 100
;control ins-pos-pc "Insert at % of detected silence piece" real "" 100 0 100
  1. That line:
(setq snd-ratio (/ (constrain add-snd-pc 0 1000) 100.0))

by this:

(setq snd-ratio (/ (constrain add-snd-pc 0 1000) 100.0))
(setq pos-ratio (- 1 (/ (constrain ins-pos-pc 0 1000) 100.0)))
  1. And that line:
(push (list (/ count lo-rate) (/ sil-count lo-rate)) sil-list))

by this:

(push (list (- (/ count lo-rate) (* (/ sil-count lo-rate) pos-ratio)) (/ sil-count lo-rate)) sil-list))

Thinking about language tutorial patterns like “Native sentence - Pause - Foreign translation” or “Question - Pause - Answer”, the fourth way to stretch the pauses have to be here:

  • The amount of silence inserted as a proportion of the length of the answer, that sounds after the silent pause.

When we have decided on the desired features, I propose this as the next plugin to be promoted to http://wiki.audacityteam.org/wiki/Download_Nyquist_Plug-ins. Then we would have a logical group Extend Silence, Trim / Extend, Trim Silence.


Gale

This is fun, thanks! I experimented with it to extend guided meditation sessions. In my case and for this speaker and recording setup, good thresholds seem to be -60 dB and a min detected silence of at least 5 seconds (not to introduce weird silences in the middle of sentences). To extend a 10 min session into 20 min, I then extend the silence by 100% of its own length + 100% of the preceding sound.

However:

  • I have various silences which can’t be reliably auto detected by thresholds and then need to move silences around manually. Being able to specify the silence locations by a series of labels in order to apply the effect automatically based on them, could be useful. Alternately, I need to place my labels then make sure that there is indeed a gap of 5 seconds between them (and none within), before applying the effect.
  • the plugin doesn’t allow a min detected silence of more than 10 seconds, nor a % of detected silence or a % of previous sound of more than 100%, although such values would be valid. (I guess I could fix this for myself by editing the script, but this should probably be fixed before being offered as a standard.)
  • the progress bar doesn’t estimate correctly how long the effect will take to apply (gets to 100% then waits several more seconds before finishing)

Unfortunately Nyquist plug-ins do not (yet) have the ability to read labels.


You could modify the plug-in by opening it in a plain text editor (for example: NotePad++) and change the line:

;control min-dur "Min detected silence (seconds)" real "" 1 0.1 10.1

to something like:

;control min-dur "Min detected silence (seconds)" real "" 1 0.1 60

This increases the maximum setting of “Min detected silences (seconds)” to 60 (1 minute). The three numbers at the end are: “default” (1 second), “minimum value” (0.1 second), “maximum value” (60 seconds).

Unfortunately I don’t think that can be fixed, at least, not without some major changes to how Audacity implements Nyquist plug-ins. The plug-in code itself runs very quickly, as is shown by the progress bar, but all that the plug-in does is to calculate where and how much silence to add. Audacity then needs to copy the entire audio data into RAM, insert the silences, write the resulting audio to disk and redraw the waveform. It’s this latter part that takes the time, but that all occurs outside of the progress loop that is being timed.

Hi,
First let me thank you for such a useful plug-in. Actually I first searched and came across your plug-in and then installed Audacity only to use this plug-in. :sunglasses:
I want to add silence more than 100% of previous sound duration. How should I edit the code to remove or increase that maximum? Not sure if this is the answer:
https://forum.audacityteam.org/t/extend-silences/34612/10

Thanks

Firstly, it is essential that a “plain text” editor is used when editing Nyquist plug-ins. On Windows, NotePad++ is ideal.

To increase the available % range from “0 to 100” to “0 to 200”, find this line (line 19):

;control add-sil-pc "Add % of detected silence duration" real "" 0 0 100

and change it to:

;control add-sil-pc "Add % of detected silence duration" real "" 0 0 200

The three numbers at the end of that line are: default, minimum, maximum.

Thanks for the hint. Actually what I was looking for was the next line (line 20). In case any other one might have the same question:

;control add-snd-pc "Add % of previous sound duration" real "" 0 0 100

Let’s assume several seconds of speaking in the audio won’t go below the average silence threshold you’ve set. So no silence will be inserted in that part and that long chunk will be harder to listen and repeat. In such case if you set a higher threshold, the whole audio file will be divided into very short segments which is impractical.
It would be great if an option was added to “Extend silences” plug-in for setting a limiting duration and a higher second threshold. If sound segments get longer than that, then it’ll search inside them for a higher silence threshold and this way segmenting them to shorter pieces like the rest of audio.

Select the part of the track where you want one lot of settings and apply, then select another region and apply with different settings.

If you have several audios with several of those high threshold segments in them, manual scanning, selecting and running effect for each segment will take a very long time.