Using Praat for analysing a speech corpus

Mietta Lennes

VISPP Summer School 2005, Palmse, Estonia

Exercises

Each exercise is associated with a folder that contains, e.g., sound files and Praat script files. The folders (excluding sound files, see below), as well as an updated version of these exercises, can be downloaded from http://www.helsinki.fi/~lennes/vispp/

(Right-click on each file name and select Save target as… from the drop-down menu.)

IMPORTANT: Due to copyright reasons, the sound files (narrative1.wav – narrative14.wav) are not available at the same web address. In order for all the scripts to work without modifications, the sound files should be downloaded separately from the website of the Handbook of the IPA (please download the Hindi examples and copy the contents of the subfolder Narratives into the corpus subdirectory of each exercise folder). If you want to continue the phonetic labeling of the Hindi corpus, you can find a phonological transcript of the narrative in the printed Handbook of the IPA.

The Praat program, the command line version for Windows, and the phonetic font SIL Doulos IPA can be downloaded via Praat home page, http://www.praat.org

PART I. Getting familiar with Praat

These exercises are only for those who have little experience in working with Praat. However, try to make sure you have a basic understanding of how Praat works before moving on to the second part of the exercises.

In Praat, you can usually do acoustic analyses in two ways: either in an editor window (select an object and press Edit), or through the Object window, by selecting Sound object and producing a new analysis object from it with the various buttons. When you start analyzing new material, you can use the editor windows to browse through and explore your corpus, to switch on different analysis displays, try out different analysis parameters, and to annotate your corpus. The commands in the Object window are to be preferred during the final stages of your experiments: e.g., in Praat scripts, or when drawing pictures for publications.

Viewing and playing sounds

1.  Open Praat. Open a sound file (e.g., narrative1.wav) in the folder exercise1/corpus (Read:Read from file…) and view it in the SoundEditor (press Edit). Make sure you know how to select and play different regions of the sound (click on the grey horizontal bars below the analysis views), and how to zoom in and out (using the short-cut buttons at the bottom right corner).

Calculating acoustic analyses (Pitch and Formant)

2.  Calculate a Pitch analysis object for a Sound object. This is done through the Object window: select a Sound from the list and press Periodicity:To Pitch… If necessary, select a minimum and maximum pitch parameters (floor and ceiling) that are suitable for the speaker.
Try to find out by a Query command, which time point in this Pitch analysis has the maximum (highest) pitch.
Now select the Sound object and view it in the SoundEditor again. Open another editor for the Pitch object and make sure the small Group square in the bottom right corner is checked. Move the two editor windows and resize them so that you can view one on top of the other.
Click on the highest value in the Pitch editor window and try to see where this value is located in the SoundEditor. Compare the time point with your previous Query result. What kind of Query commands are available for a Pitch object in the SoundEditor window?
In the SoundEditor, switch on the Pitch analysis view (Pitch:Show pitch). Adjust the Pitch analysis settings in the SoundEditor so that they correspond to the settings you gave when calculating the Pitch object, which is shown in the other window. The two Pitch curves should now look quite similar.

Please note that the SoundEditor and the Object window are separate environments for calculating the analyses, and the parameters can be different in each!

Formant analysis from a vowel

3.  In the SoundEditor, switch on the Formant analysis view (Formant:Show formants). Adjust the formant analysis settings if necessary. Select a portion of the sound that contains a clearly pronounced vowel segment. Extract this selected region to the Object list (File:Extract selection). In the Object window, calculate a Formant object from the new Sound (Formants&LPC:To Formant (burg)…), using similar analysis parameters than those within the SoundEditor. Try different Draw commands for plotting the Formant object into the Picture window.

Saving analysis objects and other files

All Praat objects can be saved by first selecting the object and then a suitable command from the Write menu. Praat suggests that the filename be the name of the object plus an extension according to object type, e.g., narrative1.Pitch or vowel.Formant. Regardless of the file name, any files that were saved with Praat can be opened again with Praat on any other machine.

4.  Try saving the Pitch and/or the Formant object you just calculated. (Tip: Write:Write to short text file… makes smaller files than Write:Write to text file…)

Practise annotation

5.  First, create a TextGrid object for the Sound object: select the Sound and press Annotate:To TextGrid…. Let’s make three annotation tiers for now: type phone word utterance to the All tier names line in the dialog box. Then press OK. This procedure creates a TextGrid object that has the same name and duration as the corresponding sound.
To edit the TextGrid together with the sound, select them together in the Object list and press Edit.

The upper part of the TextGrid editor window corresponds to an ordinary SoundEditor, and the three annotation tiers are seen at the bottom. To insert a boundary to one of the tiers, click at a point in the upper part of the window, then click the small circle on top of the annotation tier that you are working on, and a new thick vertical boundary will appear. To insert a label text into an interval, click on the interval in the annotation tier and just type!

When you are “seriously” annotating, you should of course save your work every now and then:

6.  In the TextGrid editor, select File:Write TextGrid to text file…, or first select the TextGrid object in the Object list and select Write:Write TextGrid to text file…

PART II. Scripting

Praat scripts are in fact computer programs that you can run with Praat. All buttons and menu commands that you usually select or click with the mouse, can also be used as commands in the Praat scripting language. You can use the History to find out how the Praat scripting language looks.

7.  In the Object window, select Control:New Praat script. This opens a script editor window for you. Now select Edit:Paste history. Everything that you have done since you last opened Praat is now shown in the scripting language! Try to read each line and to understand which function you were performing at that point. You could even try to run everything or a few lines again (select Run:Run (selection)).

A script is executed line by line. It is also possible to include comment lines in the script to help you remember what the script does at different stages. Comment lines are not executed by Praat. Comments begin with one of the characters #, ! or ;

When you need to check what kind of script line you should use to perform a specific function, you can first clear the history by selecting Edit:Clear history in the script editor window, then perform the required command manually, and finally go back to the script editor and select Edit:Paste history.

8.  Open a new script window in Praat (Object:New Praat script). Copy the following line to the script window:

printline Hello, you just executed your first Praat script!

Then select Run:Run in the menu of the script window. What happens?

9.  Variables are places where you can store numbers or text to be used later within the same script. Variable names cannot contain special characters or spaces, and a variable name needs to begin with a low-case letter, e.g., myVariable, this_is_another_variable. If a variable contains text (a string variable), the variable name should end with the character $, e.g., string$. When you want to access the contents of a variable, you need to put the variable name in single quotes: 'myVariable' or 'string$'. Try to run the following script:

weekday$ = "Friday"

printline Today is 'weekday$'.

It is also possible to ask the user for the initial contents of some variables. This is done by placing a form at the beginning of a script. Try this:

form Sum of two numbers

real Number1 53

real Number2 47

sentence Weekday Friday

endform

sum = number1 + number2

printline 'number1' + 'number2' is 'sum'. Today is 'weekday$'.

Now you are ready to try out some more complex Praat scripts!


PART II. Going through the motions of speech corpus annotation and analysis

This part of the exercises provides examples on how you can utilize multiple layers of annotation and presents a few basic building blocks that you may use to analyse your own speech corpus.

The first phase in annotating a newly recorded speech corpus is to transliterate it (that is, to make an orthographic transcript of the speech). You can type a transcript to an ordinary text document (e.g., in MS Word), but you cannot efficiently use a transcript that is not linked to the timelines of the corresponding audio files. Moreover, it is much easier to listen to the recorded sound if you use an annotation tool such as Praat. With Praat, each audio file in your corpus should be associated with a Praat TextGrid file. It is also preferable to use the same name for both the sound file and its TextGrid pair, e.g., example.wav and example.TextGrid. This way, your Praat scripts will know which sound file is described in each specific TextGrid file.[1]

Example corpus

Our example corpus is the story The North Wind and the Sun read aloud by a female speaker in Hindi, consisting of 14 sound files. The written transcripts (as phonemic strings from the Handbook of the IPA as well as my shaky “transliteration” to the Latin alphabet) are available in a text file, which can be viewed with any text editor. The corpus can be found in the folder exercise1/corpus. (You should first download this folder to your machine, in case you don’t have it already.) To speed up your work, each sound file also has a TextGrid file that contains boundaries for utterances (portions during which the speaker is continuously articulating).

Before you begin…

By default, Windows hides the file extension (e.g., example.txt) from filenames that have a known type. This can cause a lot of confusion when working with Praat scripts that read and write files. It is a good idea to change this setting:

In the Windows Explorer window, select Folder Options, the View tab, and uncheck Hide extension for known file types. (Estonian: Kaustasuvandid/Vaade/Peida tuntud failitüüpide laiendid).

Step 1. Making an orthographic transcript and associating it with the recorded speech

Get familiar with the example corpus. Open the file transcript.txt with, e.g., a text editor such as WordPad, or MS Word. In Praat, open the first sound and TextGrid file pair and transfer the correct portions of text into the correct utterance intervals (listen to the utterances if you have audio on your computer). Remember to save the TextGrid when you have finished this task (you can overwrite the old file).

Example script: Draw pitch curves for all utterances in the corpus

The utterance tiers in the rest of the corpus have already been annotated for you. With this kind of utterance level annotation, you can already run some automatic analyses to the whole corpus in one go! Try to run the Praat script draw_pitch_curves_for_utterances_in_corpus.praat (available in the exercise1 folder) that draws and saves pictures of the Pitch curve of each utterance in the whole corpus. This script should produce a Praat picture file for each utterance that has a non-empty label. Praat pictures can be re-opened through the Picture window. However, you should clear the window (Edit:Erase all) before opening each new picture file. [2]

Modifying the script

How would you modify the script in order to save EPS files instead of Praat picture files?

What would you add to the script in order to draw smoothed pitch curves? (Hint: Is there a command in Praat for smoothing a Pitch object?)

Which command should you add to the script in order to produce a title above each pitch curve? (Hint: check out the menus in the Picture window. How would you do it manually?)

How should the script be changed if you wanted wider pictures?

The following task is more demanding, since it requires the use of variables: How would you change the script so that it would automatically produce a tick mark and a horizontal line at the mean pitch value into each pitch curve picture? (Hints: How do you query for the mean pitch of a Pitch object? How do you add one mark at a certain y value to the right side of a picture?)

Step 2. Using a word tier together with the utterance tier

Imagine that we have continued annotating the corpus in exercise1 and added a word tier. The new, enriched corpus now resides in the folder exercise2. Open the sound and TextGrid file pair narrative1 in exercise2 in order to see how this looks.

For some of the corpus files, word boundaries have been marked and word intervals labeled using the words in the utterance transcripts. In order for the scripts to work, the start boundary of the first word of an utterance should coincide with the start boundary of the utterance, and the end boundary of the last word with the end boundary in each utterance. You can do this by dragging a boundary in the word tier on top of another boundary in another tier; the two boundaries should “snap” together.