a script to attenuate peaks?


At the moment I process voice recordings by the same person who tends to every so often have a huge surge in tonality/volume resulting in peaks that are usually about 3-4 times higher than his normal speech. Until now I have been fixing it up manually by locating those peaks visually, selecting and attenuating those by about -5db. I find this process very inefficient and I hope that someone who’s knowledgeable in nyquist could help me write a plugin/script to do this process automatically. I looked at a lot of the existing plugins, but none do what I need.

I’ve attached a snapshot of a sample, which demonstrates those peaks.

Thank you.

Have you had a look at dynamic compressors? There’s one built-in (effects menu → compressor) in audacity. Chris compressor is also quite popular, you can get it from here: http://pdf23ds.net/software/dynamic-compressor/

There are a lot of threads on the forum about dynamic compression.

You also have the leveller effect (effects menu → leveller)

We need more information about the “peaks”:

  • Is this a pure speech signal?
  • Are there background noises or are the peaks from the voice only?
  • Maybe you could provide a short uncompressed audio example? (no MP3 please)

Instead of removing the peaks in a postprocessing step it would be much easier to use the compressor of the recording machine, what is much less work.

Answering the clarification questions:

It’s a pure speech signal

The peaks are from the voice only (not background noises)

The recording machine is just an mp3 player [cowon D2 with line-in microphone], sometimes it goes through a mixer, but there is no mechanism to do anything of a kind in it. other times it goes directly from mic to recorder.

So you would like a .wav sample? how many seconds?

Thank you.

5 seconds will be plenty.

For a mp3 recorder you can use Steve’s Soft-Clipping Limiter or the RFT-Limiter-IV.

Thank you, I’ve tried the suggested plugins, but they don’t work to the same degree of what I’ve been doing manually.

May be I can rephrase my request: I would like to raise the volume of the whole track several times but those peaks prevent me from doing that via normalize - if I amplify the whole track I get clipping, so I need to go and manually attenuate those peaks that are usually 3-5 times of higher volume than the rest of the track. and doing this manually is very slow and inefficient - trying to find a script that will do that for me. I’d define the job as find the peaks (let’s say 4 times higher than the average) and attenuate those to the average volume.

steve, I uploaded a 5sec sample here as per request:


Try the Compressor effect.
Here’s some ball-park settings:

Threshold: -8 dB
Noise Floor: -50 dB
Ratio: 8:1
Attack Time: 0.3 secs
Decay Time: 2.0 secs.
Make-up gain = tick
Compress based on Peaks = tick

That should substantially boost the overall volume without clipping those peaks.

Thank you, Steve,

Can this be scripted in nyquist?

I’m not sure what you mean “scripted” :confused:
What’s wrong with just applying the effect from the Effects menu?
or are you wanting to “batch process” multiple files?

Based on your screen shot you appear to be using a Mac. You should have a pile of AU effects in the Effect menu. If not, go to Audacity > Preferences, the Effects section and under “Enable effects” check “Audio Units”, OK the dialog then restart Audacity. You should now have the “Apple: AUPeakLimiter” in the Effect menu. The way this works is a bit odd. You set the “pre-gain”, the effect amplifies the sound by that amount then applies fast hard limiting (not clipping) at 0 dB. Based on the screen shot you could start with a pre-gain of 6 dB. If that is not enough, undo and try again with a higher setting.

– Bill

If you check the time scale on the screen shot it’s about 15 seconds per centimetre, so those “spikes” are not as transient as they first appear.
There is a 5 second audio sample a few posts back that contains one of those peaks, and the peaks are not very short - the example is about 100 milliseconds duration. I’ve not tried the Apple: AUPeakLimiter (I don’t have a Mac) but using hard limiting on this audio is likely to produce unwanted distortion, so I’d recommend using a compressor - preferably one with lookahead (such as the standard Audacity compressor). Similarly my “Soft clipping limiter” and Edgars RTF-limiter are not really suitable for this job.

@Steve: This is the problem when discussing “hard limiting” - there are many different interpretations. My experience with the AUPeakLimiter is that is uses gain reduction, not clipping, with a fast attack and release (both settable), and probably some look-ahead. So in some circles it would be called a “compressor” - one with an infinite GR ratio above the threshold and very fast attack and release.

– Bill

the problem is that the compressor settings changes I have to remember to manually set it to the values you gave me (since this is an ongoing process that will continue for months), so if I have a preset that I don’t need to manually change, that makes things much less error-prone. I hope that makes sense.

If you’re using Audacity 1.3.12 I think the compressor settings should be remembered from one usage to the next, even after restarting Audacity.

I just confirmed this in Audacity 1.3.12 on Mac. I used the built-in compressor, changed all settings and applied. I quit audacity, restart audacity again, different track, used the compressor again and all the parameters were still the ones I had selected before.

stasaudio, what’s your audacity version? On which OS are you running it?

Yes, sorry, I wasn’t clear. The last setting is remembered, but if I change the setting for doing a different kind of compression while working on a different audio content, I have to manually change the settings again and since it’s not just one entry, but 5 it’s not trivial. What I’m after is having a presets that I can choose from - e.g. [compressor speech type 1] [compressor speech type 2], etc.