How do automate a simple fade in/out process?

I’m looking for some advice on how to automate a process I’ve been doing manually on hundreds of files. I’ve started looking at programming Nyquist plugins, but before I dive in head first, I wanted to see if there is anyone out there who knows how to do this.

I’m trying to do the following with a batch of files:

  • Select the first X seconds, do a fade in
  • Select the last X seconds, do a fade out

Is there another way to do this besides writing a custom plugin? If not, can anyone make any recommendations on how to get started or point me in the right direction?

Thanks!

If you want to have a go at writing a Nyquist plug-in:

This is the basic code for the fade-in:

(setq fade-length 1.5)
(setq end (/ LEN *sound-srate*))

(abs-env
  (mult s (control-srate-abs *sound-srate*
     (pwlv 0 fade-length 1 end 1))))

In this case I’ve set the fade-in length to 1.5 seconds, though it could of course be whatever you like.
You must of course select at least 1.5 seconds of the track or you will not get a complete fade.
The code will process the entire selected region, so rather than selecting a long track and applying it, just select the first few seconds.

The basic code for a fade out is:

(setq fade-length 1.5)
(setq end (/ LEN *sound-srate*))
(setq fade-length (diff end fade-length))

(abs-env 
  (mult s (control-srate-abs *sound-srate*
     (pwlv 1 fade-length 1 end 0.0 ))))

The slightly awkward thing about this is that Nyquist effects run to the end of the selection, not to the end of the audio, so it is important that you select up to exactly the end of the track, if you want the fade-out to be at silence at the end of the track.

Alternatively, you could try this text-envelope effect: https://forum.audacityteam.org/t/text-envelope/14316/1
It is not quite ready for release, but it is fully functional.
As an example, to fade in the first 2.3 seconds of a track and fade out the last 4 seconds, you could select the entire track and use these settings:
Time units = seconds
Amplification units = dB
Initial amplification = -inf
Final amplification = -inf
Intermediate points = 2.3 0 -4 0

Steve, thank you very much for the code and ideas. I will spend some time with this and see what I come up with.

Thanks again!