Using ‘Change Tempo’ in a MACRO

After researching the forum it appears I can not use Change Tempo in a MACRO to adjust a clip to a specific ‘Length’ (in seconds).

As written, ‘Change Tempo’ appears to be written in a way that requires you to select the clip BEFORE you can fill in the ‘Length’ field. Of course, in a MACRO you want to fill in the ‘Length’ field then run the MACRO, select a specific clip, then run ‘Change Tempo’ with the preset value in the ‘Length’ field.

Does anyone know if, down the road, there might be changes in ‘Change Tempo’ to accommodate this need?

So basically, this would be a complement to the existing handy-dandy percentage from length calculator that appears when you run Change Tempo manually. However, I am not sure how many people would find this useful in a macro.

Nonetheless, you are welcome to create an enhancement issue to request that a “TargetLength” parameter be added in lieu of the existing “Percentage” parameter. See: Issues · audacity/audacity · GitHub

When you make the request, please be sure to explain to the developers why you think this would be useful.

    Thank You jademan.  I appreciate the guidance.

Just FYI… Radio stations all over the world often have clips from the field that range from 27 min to 31 min (for example). Batch converting them to 29 min would save thousands of man-hours. Right now we have to do each one manually.


I wonder if AutoHotKey could be set up to do that. Also, you could probably make the necessary calculations in Python. @steve may offer a suggestion with Nyquist.

I’ve seen these ideas surfaced in these forums over the past decades. Let’s face it, with outside programing feeding Audacity, is there anything we can’t do? Several in the past decades have already suggested (and written) Nyquist programs for specific issues (changing tempo of one track to match the time length of a second track) for example.
I’m going over to the Developer forum and suggest this feature in Change Tempo would be well received.

If you can find that Nyquist script, it’s probably easy to adapt it for your needs. Post a link, or the actual code, here, and I’ll be happy to take a look.

Below are a couple of scripts. However, I’m not trying to solve this problem just for me. There are thousands of Low Power radio stations all over the world manned by volunteers and some lowly paid staff. We all receive audio tracks ‘near’ 30 minutes, or ‘near’ an hour. And we all would like to batch “Change Tempo” them to a specified number of minutes. Skill levels are not at the level of playing with nyquist plugins. What is needed is something we can select from the Macro tool box, enter the time we want every track to be, and just run the Macro.

;nyquist plug-in
;version 1
;type process
;name "Tempo Change..."
;action "Changing tempo..."
;info "Tempo Change by David R. Sky"

;control change "Tempo change" real "factor" 0.50 0.10 8.00
;control md "Multiply or divide" int "0=multiply 1=divide" 0 0 1

(cond ((= md 0) (setf change (/ 1.0 change))
(= md 1) (setf change change)))

(force-srate 44100 (stretch-abs change (sound s)))


;nyquist plug-in
;version 4
;type tool
;name "Equal Length Tracks"
;release 2.3.2
;author "Steve Daulton"
;copyright "Released under terms of the GNU General Public License version 2"

;; Adjusts the length of the second track to match the length of the first track in
;; a project containing exactly 2 tracks.


(defun get-track-times (trk-info)
  (let (start end)
    (dolist (item trk-info)
      (when (member 'start item)
        (setf start (second item)))
      (when (member 'end item)
        (setf end (second item)))
      (when (and start end)
        (return (list start end))))))

(defun make-equal-length (info)
  (let* ((trk1 (get-track-times (first info)))
         (trk1 (- (second trk1) (first trk1)))
         (trk2 (get-track-times (second info)))
         (trk2-start (first trk2))
         (trk2-end (second trk2))
         (trk2 (- (second trk2) (first trk2))))
    (setf percent (* 100 (/ (- trk2 trk1) trk1)))
    (aud-do (format nil
                "Select: Start=~a End=~a RelativeTo=\"ProjectStart\""
    (aud-SelectTracks :track 1 :trackcount 1 :mode "Set")
    (aud-ChangeTempo :percentage percent :sbsms 1)))

(setf info (aud-get-info "tracks"))
(if (/= (length info) 2)
    "Error.\nThe project must contain 2 tracks"
    (make-equal-length info))

I added the “</>” tags to the scripts so that they display the correct code formatting.

The first of those scripts stretches the selected audio by resampling. This is similar to the “Change Speed” effect and will alter both the length and pitch of the sound. For small amounts of stretching (3% or less), this should be the preferred approach because this kind of stretching is almost lossless for sound quality, and the change in pitch will not be noticeable. As well as being better sound quality, it is also much faster than “Change Tempo”.

For stretch factors much above 3%, the change in pitch, when using “Change Speed”, will be noticeable in the voice, so a “Change Tempo” type effect will be needed.

The second script uses “Change Tempo”. This is the one that we would need to adapt if you need to stretch by more than +/- 3%.

Which one would you like me to adapt for use in a macro?

Neither. I am going to suggest to the developers that they develop a ‘version’ of Change Tempo that will allow us to specify a track length in seconds then run it in a Macro on many tracks. This is not just for me; it is for the thousands out there in small radio stations that need this feature. This has to be a tool when creating a Macro just like ‘set’, ‘cut’, … etc.
Thank you for wanting to assist me in dealing with this. But, as I said it is not just my problem. This has to be one of the many tools available in the tool box when building a new Macro.


The best way to send feature requests is to add an “Enhancement Issue” to Audacity’s GitHub: Issues · audacity/audacity · GitHub If the developers like the idea, than the feature may be added eventually, but it is unlikely to happen any time soon.

In the mean time, I like your idea, so I’ve made a plug-in for the purpose that you describe. It’s called “Change Tempo to Length” and it can be downloaded from my blog: Stretching audio to length | AudioNyq
To use the effect in a macro, the audio that you want to stretch must be selected, then apply the effect.

This shows a basic macro that uses the plug-in to batch process files, stretch each file to 30 seconds duration, and export as WAV:

I also raised a bug report for the “Tempo Change…” plug-in that you mentioned.

This is very kind of you to do this. I’ll take advantage of it. I do want this available to all us poor volunteers supporting small radio stations so I certainly am going to put this in front of the good developers. I know it would take some time. I’m quite sure those developers have enough on their plate to keep them busy 24/7/365.
Thanks again.

Our station’s volunteers have started using ‘Change Tempo to Length’. We have cleared a backlog of almost one thousand interviews. This would have taken almost a half a year of daily work. With your plugin it took only one volunteer 4 hours. Thank you sooooo much!!!

Plus half a day for me to write, test, document and upload the plug-in. That’s a good return on the invested time - glad I was able to help :slight_smile:’t-know-from-where-to-start-exactly-Any-suggestions

Right now the programming language ‘Python’ is, by far the most used.

This topic was automatically closed after 30 days. New replies are no longer allowed.