parselmouth.praat.run

Contents

parselmouth.praat.run#

parselmouth.praat.run(script: str, *args, **kwargs) object#
parselmouth.praat.run(object: parselmouth.Data, script: str, *args, **kwargs) object
parselmouth.praat.run(objects: List[parselmouth.Data], script: str, *args, **kwargs) object

Run a Praat script.

Given a string with the contents of a Praat script, run this script as if it was run inside Praat itself. Similarly to parselmouth.praat.call, Parselmouth objects and Python argument values can be passed into the script.

Calling this function roughly corresponds to the following sequence of steps in Praat:

  1. Zero, one, or multiple parselmouth.Data objects are put into Praat’s global object list and are ‘selected’.

  2. The Python argument values are converted into Praat values; see call.

  3. The Praat script is opened and run with the converted values as arguments; see Praat: “Scripting 6.1. Arguments to the script”.

  4. The results of the execution of the script are returned; see below.

  5. Praat’s object list is emptied again, such that a future execution of this function is independent from the current call.

Note that the script will be run in Praat’s so-called ‘batch’ mode; see Praat: “Scripting 6.9. Calling from the command line”. Since the script is run from inside a Python program, the Praat functionality is run without graphical user interface and no windows (such as “View & Edit”) can be opened by the Praat script. However, the functionality in these windows is also available in different ways: for example, opening a Sound object in a “View & Edit” window, making a selection, and choosing “Extract selected sound (windowed)…” can also be achieved by directly using the “Extract part…” command of the Sound object.

Parameters:
  • object (parselmouth.Data) – A single object to add to the Praat object list, which will be selected when the Praat script is run.

  • objects (List[parselmouth.Data]) – Multiple objects to be added to the Praat object list, which will be selected when the Praat script is run.

  • script (str) – The content of the Praat script to be run.

  • *args – The list of values to be passed as arguments to the Praat script. For more details on the allowed types of these argument, see call.

Keyword Arguments:
  • extra_objects (List[parselmouth.Data]) – Extra objects added to the Praat object list that will not be selected when the command is called (default value: []).

  • capture_output (bool) – Intercept and also return the output written to the Praat info window, instead of forwarding it to the Python standard output; see below (default value: False).

  • return_variables (bool) – Also return a dict of the Praat variables and their values at the end of the script’s execution; see below (default value: False).

Returns:

A list of parselmouth.Data objects selected at the end of the script’s execution.

Optionally, extra values are returned:

  • A str containing the intercepted output if capture_output=True was passed.

  • A dict mapping variable names (str) to their values (object) if return_variables is True. The values of Praat’s variables get converted to Python values:

    • A Praat string variable, with a name ending in $, is returned as str value.

    • A Praat vector or matrix variable, respectively ending in # or ##, is returned as numpy.ndarray.

    • A numeric variable, without variable name suffix, is converted to a Python float.

Return type:

object