python mod-script-pip : render mp3

Hello, I’m trying to use Audacity’s mod-script-pip for rendering audio selections to an mp3 file (and metadata tag the file as well if possible).

I got mod-script-pip working, and am testing it by running the pipeclient.py file on my windows 10 cmd terminal; which lets me enter commands that effect my open Audacity window.

My starting off point is having a part of my track selected like so:

if I run

Export: Mode=Selection Filename=renderFIilenameTest.mp3 Channels=2

It will begin the process of rendering that selection; which opens this first window:

At this point my console says the command timed out and i can enter another command, is there some way to click the ‘save’ button and change parameters like quality for rendering?

I found on this page:
https://ttmanual.audacityteam.org/o/man/scripting.html

Something called ‘MenuCommand’, which says ‘Executes a ‘menu command’, using the system that controls the Audacity menus’. I tried using that with a command like

MenuCommand: CommandName=Save

once the window is opened but my console just times out and nothing happens.

Is there a command or series of commands I could use to render the selection from my first pic into an mp3 file? I’m trying to do this completely programmatically with no user input, so im open to hearing any methods of selecting/clicking buttons in the popup windows when i try to render a selection, or skipping them alltogether.

(this is also my first attempt at scripting audacity in python, so any help is appreciated, thanks)

Handle the file navigation in Python, then use the Import2: command
(See: https://manual.audacityteam.org/man/scripting_reference.html#Extra:_Scriptables_II)

thanks steve, are you talking about exporting the file, then reimporting it?

Ultimately my goal is to render each selection from my track, so for pic1 i would have three different mp3 files for each of the three selections.

Maybe some way I could seperate each section into its own track and render those? I feel like there’s got to to be some way to run commands to press the buttons in the popup windows for exporting audio selections

Oops, no. I meant, use the “Export2:” command. :blush:

Note that you must use the full file name (including the full file path) with Export2:

Thank you, the command

Export2: Mode=Selection Filename="C:\Users\marti\Documents\projects\audacity-script\test1.mp3" Channels=2

Was able to render the individual selection. Is there some way i can see all the availaible flags for the export 2 command? I’m curious if there are quality options / any potential mp3 metadata options

Got my program to render individual selections at high quality with this:

Export2: Mode=Selection Filename="C:\Users\marti\Documents\projects\audacity-script\test13202.mp3" NumChannels=2

found the NumChannels flag by running

Help: Command=Export2

which shows this:

{ "id":"Export2", "name":"Export2", "params":
    [
      { "key":"Filename", "type":"string", "default":"exported.wav" },
      { "key":"NumChannels", "type":"int", "default":1 } ],
  "url":"Extra_Menu:_Scriptables_II#export",
  "tip":"Exports to a file." }

I think this solves my question, i wanted to tag the mp3 file with stuff like title/year/album/artist but i dont think thats possible with export2, so i might just use a separate python3 library

The documentation: Scripting Reference - Audacity Manual
Third column (“Parameters”) lists the available arguments.
This documentation is generated from the Audacity code, so although the descriptions are terse, it should be accurate. (Let us know if you find any errors so they can be corrected.)

or, as you say, with the Scripting command
Help: Command=“string”


“Export2:” exports the selected audio. “Mode” is not a recognised parameter - it will be ignored.

Note that for formats that take settings (such as MP3), Export2 uses the format settings that were last used.
It is however possible to change that, using the SetPreference: command. For example, to set MP3 format to 128kbps CBR, you need two commands:

SetPreference: Name="FileFormats/MP3RateModeChoice" Value="CBR" Reload=1



SetPreference: Name="FileFormats/MP3Bitrate" Value="128" Reload=1

The “Reload” parameter is probably only needed once, on the last “SetPreference:” command.
To find valid Preference “Name=” arguments, look in Audacity’s configuration file “audacity.cfg” (see here for the location of “audacity.cfg”: Preferences - Audacity Manual)