Audacity Python



Free, open source, cross-platform audio software. Audacity is an easy-to-use, multi-track audio editor and recorder for Windows, Mac OS X, GNU/Linux and other operating systems. Developed by a group of volunteers as open source and offered free of charge. Amazing support community. Start coding with Python, drawing upon libraries and automation scripts to solve complex problems quickly. Use a Pre-trained Image Classifier to Identify Dog Breeds; Jupyter Notebooks, NumPy, Anaconda, pandas, and Matplotlib. Learn how to use all the key tools for working with data in Python: Jupyter Notebooks, NumPy, Anaconda, pandas,. Python is a powerful programming language used in a variety of professions, ranging from data science to web development. It's in the top 10 for 'Most Popular' and 'Most Loved' technologies (according to StackOverflow's 2016 Developer Survey ), making it a relatively friendly language for beginners. The Intermediate Python Nanodegree program teaches intermediate-level skills for programming with the Python language. It is ideal for developers interested in using Python to build more complex algorithms with greater capabilities in preparation for a variety of different roles spanning fields like data science, AI, and software engineering.

The scripting module is a plug-in for advanced users that allows Audacity to be driven from an external Python or Perl script. Commands are sent to Audacity over a 'named pipe'.
Any scripting language that supports named pipes can be used.
Obtaining mod-script-pipe

The plug-in mod-script-pipe is now shipped with Audacity and just needs to be enabled using preferences.

Follow this link for older instructions for obtaining mod-script-pipeScripting is most often used from Python.
  • The full set of Scripting Commands is listed at Scripting Reference.
  • Many of the commands in the Scriptables I and Scriptables II menus were created because they are useful in scripting.
  • Alternatives to Python scripting that use the same set of commands are:
    • Macros which follow a fixed set of steps, e.g. to convert many files from one format to another.
    • Nyquist, using the ';type tool' option. Nyquist is a built in LISP based language in Audacity.

What Scripting can do

Commands that Scripting uses are the same as in the Audacity macros feature. You can for example:

  • Select audio
  • Apply effects
  • Rearrange clips
  • Export the results.

Audacity Python Introduction

Scripting goes beyond the simpler tasks and presets of macros. Using Python scripting can for example do calculations about regions to select, or can make decisions on the basis of number and types of tracks in a project. It is also possible to build additional user interface in Python, for example an extra toolbar, and have it send commands to Audacity over the pipe.


Triple vision camera owners manual.

  • 2Getting Started

Caveats and Warnings

Line
Scripting drives Audacity from outside the Audacity user interface.
  • If you use mod-script-pipe to enable scripting, this weakens computer security, as malicious software that already has a foothold on your computer could potentially use this feature to gain more control.

See the advice below about not using scripting on a web server.

Scripting support is mainly intended for use by developers.
  • When things 'don't work' you will rarely get a message from Audacity saying why.
  • Details of the available scripting commands may well change between versions of Audacity.

There is a fuller list of limitations at the foot of this page.

Scripting is NOT SUITABLE for providing a service on a web server.
  • The reason is that Audacity does not police or sanitise the instructions that arrive on the pipe. It just attempts to obey the instructions.
  • If someone can write to the pipe they can get Audacity to read and write files and to execute code on the machine running Audacity.

Enabling mod-script-pipe allows Audacity to be controlled from outside the Audacity User Interface. In some environments, such as a web server, that is too big a security risk.


Getting Started

Enable mod-script-pipe

The plug-in module 'mod-script-pipe' is not enabled by default in Audacity, so must be enabled in Audacity preferences.

Audacity Developers

After enabling it for the first time, you will need to restart Audacity. You can then check that it is enabled and was started by revisiting the preferences page.

Audacity Python
  • Run Audacity
  • Go into Edit > Preferences > Modules
    • Choose mod-script-pipe (which should show New) and change that to Enabled.
  • Restart Audacity
  • Check that it now does show Enabled.

This establishes that Audacity is finding mod-script pipe, and that the version is compatible.

Check mod-script-pipe works

You'll also need the scripting language Python (version 3.6 or later recommended) to try out the examples.

This python script is then the best way of checking that the pipe is working:

Audacity

Using Scripting

After running pipe_test.py, you can use do(') at the python command line to try out commands. Each command name ends with a colon, and may be followed by parameters. For example: Barbie as the princess and the pauper game crack world.

PythonAudacity command line

Examples

Python Audacity Noise Reduction

More sample scripts are available here:

Audacity Python Github

  • 'pipe work' in GitHub - Sample scripts for exercising the pipe.
  • The same collection of test scripts is also available as a download from FossHub Audacity-Devel (Scripting Tests). This includes the sample audio that is used in the tests.


Commands

A table showing all the available scripting commands is at Scripting Reference.

Most commands in Audacity that are in the Audacity menus can be accessed via Scripting. Here is one example from that table:


Udacity Python Course

Scripting Id Action Parameters Description
SetLabel:Set Label..intLabel, (default:0)

stringText, (default:unchanged)
doubleStart, (default:unchanged)
doubleEnd, (default:unchanged)
boolSelected, (default:unchanged)

Modifies an existing label.

The following command in Python would set the first label in a project to the word 'Foo'.


Known Issues & Missing Features

Some current issues:
  • Scripting only works with one project at a time.
  • For some menu commands, the project window must have focus for the command to succeed.
  • It's not straightforward to get 'output' responses from commands like GetInfo. You will need to parse the results in Python.
  • The commands could have stricter parameter validation and could give better error messages when they do not work.
  • There's no consistent way to abort or interrupt commands.
  • The scripting module is not unloaded when Audacity quits. This means the script pipes are not properly deleted.
  • There may be security problems relating to the use of pipes. You're advised not to use mod-script-pipe on a system with multiple simultaneous users.