Workshop
Script Editor & Command History

Introduction

In this workshop you'll learn how to record and adapt macros. Let's assume you often need to create pictures of sound objects and their accompanying pitch contour; it's necessary that the pictures have a specific and uniform look.

The GUI approach would be, to arrange settings in the Picture window (viewport, line width, color etc.), select the sound, and draw it. Then, re-arrange settings in the Picture window, generate and select the pitch object, and draw it. To maintain consistency and uniformity you probably make notes to remember the pitch analysis parameters and the picture settings for future occasions.

With a simple macro, on the other hand, consistency is built-in and guaranteed and in the future uniform looking pictures are only one mouse click away. We'll assemble the macro step by step and suggest some possible adaptions.

Preparation

Open Praat (we'll need the Objects window and the Picture window) and load a couple of sound objects. Select one sound object.

Exercise

  • Create a new Praat script (Praat > New Praat script)
  • Clear the history (Edit > Clear history)
  • Arrange settings for the sound in the Picture window:
    • Edit > Erase all
    • Pen > Black
    • Pen > Line width...; specify 1 and confirm
    • Pen > Solid line
    • Select the viewport with the mouse; horizontal: 0 to 6, vertical: 4 to 6
  • In the Objects window choose Draw > Draw...; click Standards and confirm
  • Back in the script editor, choose Edit > Paste history to create a script including all commands from above

All GUI actions you performed as suggested above (mouse clicks and keyboard input) are translated into syntactically correct statements and inserted in the script. The script should look like this:

Erase all Black Line width: 1 Solid line Select outer viewport: 0, 6, 4, 6 Draw: 0, 0, 0, 0, "yes", "Curve"

Before you do anything else save the script! In the script editor choose File > Save, pick a directory and a file name (suffix: .praat), and confirm. To test the script, select any sound object and run the script (Run > Run in the script editor). Each time you select another sound the respective waveform should be drawn to the Picture window.

Next, you generate a pitch object and draw it above the waveform. Make sure a sound object is selected.

  • In the script editor, choose Edit > Clear history to erase the commands that we've already inserted
  • Arrange settings for the pitch contour in the Picture window:
    • Select the viewport with the mouse; horizontal: 0 to 6, vertical: 0 to 4.5
    • Pen > Blue
    • Pen > Line width...; specify 3 and confirm
  • In the Objects window choose Analyse periodicity > To Pitch...; click Standards and confirm
  • Choose Draw > Draw...; click Standards then specify the frequency range 50 to 600 Hz, uncheck Garnish and confirm
  • Back in the Picture window add some garnish:
    • Pen > Black
    • Pen > Line width...; specify 1 and confirm
    • Margins > Draw inner box
    • Margins > Marks left every...; click Standards then specify Distance: 50, uncheck Draw dotted lines and confirm
    • Margins > Text left...; click Standards then add Frequency (Hz) to the text field and confirm
  • Finally, select a viewport including the entire picture so that it can be saved or copied to the clipboard; horizontal: 0 to 6, vertical: 0 to 6
  • Back in the script editor, put the cursor in the last empty line (create one if necessary) and choose Edit > Paste history to append the new commands to the script

Now, the script should look like this (don't forget to save it!):

Erase all Black Line width: 1 Solid line Select outer viewport: 0, 6, 4, 6 Draw: 0, 0, 0, 0, "yes", "Curve" Select outer viewport: 0, 6, 0, 4.5 Blue Line width: 3 To Pitch: 0, 75, 600 Draw: 0, 0, 50, 600, "no" Black Line width: 1 Draw inner box Marks left every: 1, 50, "yes", "yes", "no" Text left: "yes", "Frequency (Hz)" Select outer viewport: 0, 6, 0, 6

That's it. From now on, every time you need a similar picture of a signal and it's pitch contour just select the sound object and run the script. If the script is not open in the script editor, choose Praat > Open Praat script..., select the script file, and run it. (There's a shortcut for scripts you need really often: In session XX you'll learn how to add your scripts to the GUI as a button or a menu item.)

Garbage removal

If you like your scripts neat and tidy, I would suggest one small addition: If a script generates new objects only for internal use, these objects should be removed at the end. Otherwise the objects list would be cluttered with unexplained objects after each script run. In our case that means if the pitch object is only used for drawing it should be removed after drawing. The easiest way to do that is to add a new line at the end of the script and type Remove. This command removes selected objects, which suits us since the pitch object is automatically selected after generation. If you don't dare typing commands yet, apply command history: Clear history, select an object, click Remove, paste history.

Practice

There are many other ways to adapt the script. To do so, just edit the script, save the new version, and run it. Suggestions:

  • To generate a red pitch contour instead of a blue one substitute Blue (line 8) with Red (see the Pen menu for other colors).
  • Adapt the line width of the pitch contour (3 in the example, line 9) to your needs.
  • Adapt the pitch range for analysis (line 10) and/or for the drawing (line 11)
  • etc.

Practice often! If you encounter a task that has to be repeated more then once or twice wait a moment, think about the task, and if it is suitable for a simple macro, generate a macro! Edit your macros: change commands and parameters or delete and rearrange lines. Make test runs, assess the effects, and adjust the script until it fits your needs. Internalize the macro workflow: Clear history—perform action(s)—paste history.

© Jörg Mayer

Last modified: