Praat Scripts

Brief intro to Praat

Here are a few Praat Scripts that I have written. Praat scripting is fairly simple, and can really improve the praat experience in two ways:

Make your workflow faster by automating repetitive tasks

Make your results more consistent by automating tasks

Here a few tips to getting started with Praat scripting:

In case you don’t already know, Praat is an acoustic analysis software
program. You can use it to view spectrograms of speech (and other) sounds,
and make many different acoustic measurements. It also includes some basic
statistics, and some routines to run basic perceptual experiments. It runs
on all major computer platforms, is free, and is fairly small in size. You
can download it from praat.org

Praat has a pretty good manual, so be sure to read it, especially the
part on scripting. There is also a
href='http://uk.groups.yahoo.com/group/praat-users/'>Praat users group,
where many of your questions can be answered. (Again, be sure you have read
the manual and searched around a bit before asking a question to the group).

A good way to learn is by example, which is why I am providing some
scripts here.

To try out these scripts, open Praat and select Open Praat
Script from the Praat menu.

3 more tips that I wish someone had told me:

Variable names cannot start with capital letters.

Whitespace matters. Sometimes a script will not work if you have a
space at the end of a line. Be careful!

Praat has a history recording function. Every time you click your
mouse, or select something from a pulldown menu, the program is
recording this and saving it. You can then paste this history into a
script using the script editor’s Edit > Paste History
function.

Example Scripts

These scripts are provided without warranty. I have tried to insert comments where appropriate, so hopefully they should be relatively easy to use. If you find any mistakes or bugs, or if you make any improvements, I would very much like to know. Please contact me at robfelty æ umich.edu

To download one script, right-click on the script name. You can also download all the scripts (along with a few helper files) as a .zip or .tar.bz2 file.

#### Robert Felty
#### 2006
#### This script comes with no warranty. Use at your own risk
## this script reads in a wordlist, in a one stimulus per line textfile,
## and prompts a speaker to speak each word in a carrier phrase
## "say X again", it records for X seconds, then writes the sound to a file
## named according to the stimulus, plus an integer from 1 to i, which
## represents the repition number.
#### N.B. MAKE SURE WHEN THIS SCRIPT IS STARTED THAT ANY RECORDING WINDOWS IN
#### PRAAT ARE CLOSED
#### ALSO MAKE SURE THAT THE OUTDIR ALREADY EXISTS

#### Robert Felty
#### 2005
#### This script comes with no warranty. Use at your own risk
## this script displays measurements taken in Praat
## For example, say you have used the VowelMeasurements script to make some
## measurements, and you have the results in a tab delimited file. This script
## will open up each soundfile and display the measurements taken in a textgrid
## window, allowing one to easily double-check the measurements, and make any
## adjustments if necessary. The adjusted measurements will be written out to a
## separate file

#### Robert Felty
#### 2005
#### This script comes with no warranty. Use at your own risk
#### This script performs a fade in on the selected part of the stimulus, starting
#### at the beginning of the selected portion, and stops at the midpoint of the
#### selected portion, at which point it reaches the average intensity of the
#### selected portion.
#### It then writes out the faded in sound to a new file

#### Robert Felty
#### 2005
#### This script comes with no warranty. Use at your own risk
## This script performs a filter on a highlighted section of a sound object.
## The intended use is to make intervocalic consonants sound like coda
## consonants.
## For fricatives, the filter created starts at the midpoint of the fricative,
## at the average intensity of the fricative, and scales it down to zero
## intensity with a linear (dB) function.
## TODO: tell user why script fails (e.g. if nothing is highlighted, or no
## object is selected

#### Robert Felty
#### 2006
#### This script comes with no warranty. Use at your own risk
## this script loops over a directory which contain all sound files,
## and for each file, it opens it up, makes a spectrogram, and allows
## the user to annotate it with a text grid, and the annotation is displayed
## with the spectrogram along with the intensity contour and a pitch contour
## currently, the picture is simply copied to the clipboard, but it could also
## be written to an .eps file, or the textgrid could be written to a text grid
## file, to be used for later processing

#### Robert Felty
#### 2005
#### This script comes with no warranty. Use at your own risk
## this script accomplishes two tasks -
## 1. cut stimulus from carrier phrase and append silence
## then write to .wav file
## 2. make some basic measurements on the vowel
## The first part requires the user to highlight the portion of the sound file
## which contains the stimulus
## The second part requires the user to highlight only the vowel portion

#### Robert Felty
#### 2005
#### This script comes with no warranty. Use at your own risk
## this script accomplishes two tasks -
## 1. cut stimulus from carrier phrase and append silence
## then write to .wav file
## 2. get midpoint of vowel
## The first part requires the user to highlight the portion of the sound file
## which contains the stimulus
## The second part requires the user to highlight only the vowel portion
## The script loops over a directory containing .wav files, opens each one
## displays it in a textgrid, then asks the user to select a portion of the
## sound to be cut out, and then to select the vowel, and it marks the midpoint
## of the vowel. We used this script to edit stimuli for a perceptual experiment
##

#### Robert Felty
#### 2005
#### This script comes with no warranty. Use at your own risk
#### This script performs a filter on a highlighted section of a sound object.
#### The intended use is to make intervocalic consonants sound like coda consonants.
#### For fricatives, the filter created starts at the midpoint of the fricative,
#### at the average intensity of the fricative, and scales it down to zero intensity with a
#### linear (dB) function.

#### Robert Felty
#### 2008
#### This script comes with no warranty. Use at your own risk
## Mark segment boundaries for CVCs
## This script loops over a directory, opening each .wav file one at a time,
## and creates a textgrid, then opens the textgrid and sound together. At this
## point, the user can add 2 points to the textgrid marking the boundaries
## between phonemes. A pause dialog box is opened (it may be hidden behind the
## textgrid window)). Clicking on continue will write the measurements to the
## specified file. The current sound object will be deleted, and the next file
## will be opened.
##

#### Robert Felty
#### 2008
#### This script comes with no warranty. Use at your own risk
## Measure spectral moments
##
## This script loops over a directory, opening each .wav file one at a time,
## and creates a sound object, then opens it. At this
## point, the user can select a portion (a vowel or a consonant)
## to be measured. The script then creates a spectral slice with the specified
## window width centered at the midpoint of the selected region.
## Then the script measures the first 4 spectral moments of the spectral slice.
## A pause dialog box is opened (it may be hidden behind the
## textgrid window). Clicking on continue will write the measurements to the
## specified file. The current sound object and the spectrum object will be
## deleted, and the next file will be opened.

#### Robert Felty
#### 2005
#### This script comes with no warranty. Use at your own risk
## This script is to be used for measuring vowels. It takes a highlighted
## section of a sound object (which should be the vowel, as determined by the
## pitch tracker), and takes the following measurements:
## duration
## F1, F2, F3 in a 30ms window centered on the midpoint of the vowel
## Peak and average intensity
## Initial, Final, Peak, and average pitch
## It uses Praat's default settings for formant and pitch analysis

#### Robert Felty
#### 2005
#### This script comes with no warranty. Use at your own risk
## This script is to be used for measuring vowels. It takes a highlighted
## section of a sound object (which should be the vowel, as determined by the
## pitch tracker), and takes the following measurements:
## duration
## F1, F2, F3 in a 30ms window centered on the midpoint of the vowel
## Peak and average intensity
## Initial, Final, Peak, and average pitch
## It uses whatever pitch and formant settings the user currently has set