0

I want to script Audacity for routine tasks (compression, limiting, loudness normalization). I followed these instructions and used this pipe-test script. The result is OK:

$ python3 pipe_test.py 
pipe-test.py, running on linux or mac
Write to  "/tmp/audacity_script_pipe.to.501"
Read from "/tmp/audacity_script_pipe.from.501"
-- Both pipes exist.  Good.
-- File to write to has been opened
-- File to read from has now been opened too

Send: >>> 
Help: Command=Help
Rcvd: <<< 

Send: >>> 
Help: Command="GetInfo"
Rcvd: <<< 
{ "id":"Help", "name":"Help", "params":
    [ 
      { "key":"Command", "type":"string", "default":"Help" },
      { "key":"Format", "type":"enum", "default":"JSON", "enum":
          [ "JSON", "LISP", "Brief" ] } ], 
  "url":"Extra_Menu:_Scriptables_II#help", 
  "tip":"Gives help on a command." }
BatchCommand finished: OK

I modify the script commands to:

do_command("SelTrackStartToEnd")
do_command("Amplify: Ratio=0.8")

If I comment the second command, so only the first runs, nothing is selected. If uncomment the second to run both, I see the track getting selected on Audacity and then it crashes. The shell gets stuck:

$ python3 pipe_test.py 
pipe-test.py, running on linux or mac
Write to  "/tmp/audacity_script_pipe.to.501"
Read from "/tmp/audacity_script_pipe.from.501"
-- Both pipes exist.  Good.

^CTraceback (most recent call last):
  File "pipe_test.py", line 40, in 
    TOFILE = open(TONAME, 'w')
KeyboardInterrupt

I tried this 3 times with the same result. When I re-open Audacity, I see an option to recover projects:

Audacity recover projects notification

I am running the latest Audacity (2.4.2) and macOS Mojave 10.14.6 with all updates installed.

How can I script Audacity?

Update

Following a comment in Automate pre-processing of sound (noise reduction, compressor, limiter), I tried the same steps on Audacity 3.0.0 and get the same results: the script works for just selecting the track and crashes when amplifying. The shell no longer gets stuck and has a slightly different output:

$ python3 audacity_pipe_test.py 
pipe-test.py, running on linux or mac
Write to  "/tmp/audacity_script_pipe.to.501"
Read from "/tmp/audacity_script_pipe.from.501"
-- Both pipes exist.  Good.
-- File to write to has been opened
-- File to read from has now been opened too

Send: >>> 
SelTrackStartToEnd
Rcvd: <<< 

Send: >>> 
Amplify: Ratio=0.8
Rcvd: <<< 
BatchCommand finished: OK

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.