Macro to change tempo to specific length

Hello all,

I’d like to create a macro to change tempo in order to change the length of a recording to 60 seconds (which means varying percentage changes depending on the length of the original). When using the feature normally (without a macro), I just put the desired length of the clip in the box at the bottom but when creating a macro it seems as if the only parameter I can specify is a percentage change. Does anybody have any ideas on how to create a macro that works the way I’d like it to?

(Audacity 2.3.0)

Ross in Colorado

I assume that you want to change the tempo without changing the pitch?
If so, you will need to make a “Nyquist Macro”

Unfortunately this does not appear to be possible in Audacity 2.3.0 or earlier.
Release candidates for Audacity 2.3.1 are scheduled to become available around the end of January.

This code should work in Audacity 2.3.1 and later:

;nyquist plug-in
;version 4
;type process
;name "Stretch to length"
;action "Stretching..."
;author "Steve Daulton"
;release 2.3.1
;copyright "Released under terms of the GNU General Public License version 2"

;; Released under terms of the GNU General Public License version 2:
;; For information about writing and modifying Nyquist plug-ins:

;control target "Target length" float-text "seconds" 60 0 nil
;control sbsms "Use highquality stretching" choice "No,Yes" 0

(let* ((start (get '*selection* 'start))
       (end (get '*selection* 'end))
       (dur (- end start)))
  (if (= target 0)
      "Error.\nTarget length cannot be zero."
      (prog ((percent (* 100 (/ (- dur target) target))))
          ((< percent -95)
            (return "Error.\nTarget length too large."))
          ((> percent 400)
            (return "Error.\nTarget length too small."))
            (setf command
                  (format nil
                          "ChangeTempo: Percentage=~a SBSMS=~a"
            (aud-do command)
            (return ""))))))

and here it is as a file that may be installed in the same way as any other Nyquist plug-in:
stretch-to-length.ny (1.24 KB)
When installed, the plug-in will appear in the Effect menu.

Hey Steve,
That’s amazing! As soon as I get 2.3.1 I’ll give it a try. Can I cut/paste macro code directly into the Audacity somewhere?

The way to use it is to install the “stretch-to-length.ny” file as a plug-in (see:

When installed (and enabled), you can either use the plug-in directly from the Effect menu, or include it in a Macro in the same way as including any other effect.

Got it…what’s your guess as to when fully-tested version of 2.3.1 will come out? Since use of Audacity is “mission-critical” for my work, I probably can’t take risk of installing alpha/beta.

Audacity 2.3.1 is already fairly well tested, but there’s a problem with the Mac version. The Mac version will be the first 64-bit version for Mac, but we don’t yet have a compatible 64-bit FFmpeg. One of the developers is currently working on this, and hopes to have it resolved within the next couple of weeks. The official release is expected to be about 3 weeks after that, so all being well, that will be early February.

I think that most of the Audacity testers are already using 2.3.1 on Windows for production work, so I’d suggest getting 2.3.1 as soon as the “Release Candidate” is available - just be sure to make backups as you work, which you should do anyway :wink:

Hey Steve,

Is it possible to create a macro to run a macro?

In other words, could I create a macro that runs the macro you created here as well as performing an amplify function?

I record commercials at home and typically I have to make them a few seconds shorter and increase the amplification.

Finally, would it be possible to create a macro that trims off any silence between 0:00 and the first sound?


The Macros that you create in the “Tools > Macros…” interface: I shall refer to this type of Macro as a “normal” Macro.
A “normal” Macro can call other macros.

“Nyquist Macros” can call most other Macros, but cannot call “Nyquist Macros” or any other Nyquist plug-ins. If a Nyquist effect (plug-in) is included in a Nyquist Macro, the effect is ignored. Nyquist cannot call Nyquist.

Yes you can call the Nyquist Macro that I posted here in a “normal” Macro, but you can’t call it from a Nyquist script (a Nyquist Macro or a regular Nyquist plug-in).

You could do that by installing this “Trim Silence” plug-in: Missing features - Audacity Support
Once it is installed, you could call this plug-in from a “normal” Macro.