Batch Processing Tempo Change Script

Hi, I am new to Audacity. I have a request for someone with experience in scripting to assist me in creating a script to batch change tempo for a large folder of files. Each file needs to be changed to 5 minutes. Each file is slightly different in length…some are 5 minutes 10 seconds, some are 4 minutes 45 seconds, etc. My request is to run a script for a folder of files and have each file have the tempo changed to exactly 5 minutes. I have tried creating a macro and it does not change the tempo based on time, only percentage. Any help would be greatly appreciated.

I am using Windows operating system.

Is your question about the same thing as this:
Is it a school project / homework?

For practical purposes, and as I wrote in the other topic, surely it will be better for the listener if the audio plays at the correct speed, even if the sections are a little more or less than multiples of 5 minutes :confused:

No, this is not the same project. I am trying to get each audio file to be 5 minutes in length. Please see the attached video to demonstrate what I am doing manually. I have hundreds of files that I would like to batch change the tempo to a length of 5 minutes.

Is there a purpose / reason for doing that? Maybe there’s an easier way.

Yes, there is a reason. We have a proprietary audio player that adjusts speed in realtime and the algorithm uses the length of the file to properly adjust the pitch and speed in realtime. So, each file must be precisely 5 minutes in length.

It sounds like it would be much simpler if your “proprietary audio player” just played the audio at normal speed and supported different length files. Nevertheless, to do what you want, create a “Nyquist Macro” (See:, and use it in a (normal) Audacity macro for batch processing (See:

This Nyquist code calculates the required percentage, and calls the Change Pitch effect, using the calculated percentage.
(Semicolons are used to indicate comments).

;; Percent change = 100 * (OriginalLength - NewLength) / NewLength

(setf nlen 300) ; new length
(setf olen (get-duration 1))  ; original length
(setf percent (* 100 (/ (- olen nlen) nlen)))

;; Apply Change Tempo.
;; (Change :sbsms to 0 if you want to disable the "high quality" setting).
(aud-do-command "ChangeTempo" :percentage percent :sbsms 1)

;; Return an empty string as a no-op.