In the last workshop (Generating Output) you practiced writing literal numbers and strings to Praat Info. Now, you'll widen your output skills using variables. And of course, you'll practice variable usage in other contexts.
Start Praat and open a new Praat script. Later, we'll need a sound object containing at least one vowel.
ExerciseWarm up: Invent a valid variable name and assign a number. Generate the following output:
- clear Praat Info and write out the name and the content of the variable
- add a line and write out the content of the variable multiplied by 2
- assign the content of the variable divided by 2 to a new variable and write out the content of the new variable
- assign a string to a new variable and write out it's content, followed by both numeric variables, separated by spaces
- attach the content of your first numeric variable to the string variable as a string and write it out
Now, let's try something useful: A script that measures—within an editor selection—the mean and standard deviation of a formant and moves the curor to the formant maximum. We need a sound object in the sound editor with activated formant analysis (
Formant > Show formants). Since we'll start with a selection in the sound editor, we implement this as an editor script. Here's a step-by-step description of what the script will do:
- Starting point: a selected vowel in the sound editor
- Extract selection (windowed)
- In the shell, run formant analysis of extracted vowel
- Query formant object for
- standard deviation
- and time of formant maximum
- Back in the editor, move cursor to time of formant maximum
- Write out query results
To get started, open a new editor script (
File > New editor script) and clear the history. (1.) Select some vowel. (2.) Extract the selection using a Hamming window and preserve times (
File > Extract selected sound (windowed)...); paste and clear history. This is how your script should look:
(3.) In the shell, run a formant analysis of the extracted sound slice (
Analyse spectrum > To Formant (burg)...). Use standard settings but adapt 'Maximum formant' to your speaker. Test the script and inspect the resulting formant object. When you are satisfied paste and clear history. The following listing suits a male speaker:
To be able to quickly switch between male and female speakers, assign 'Maximum formant' to a variable at the beginning of the script and apply the variable in the fromant analysis.
(4.) With the formant object selected, explore the
Query menu. Query the first formant for the (a.) mean, (b.) standard deviation, and (c.) time of maximum, then paste and clear history. Edit the script to assign the query results to variables.
If you are interested in the second formant instead of the first, you would have to edit 3 query commands. To correct this, invent a variable at the beginning to specify the formant and apply this variable in the query commands.
(5.) Back in the editor, use your time-of-maximum variable (mine is called
tmax) to move the cursor to the time of the specified formant's maximum (if you never moved the cursor without the mouse check
Select > Move cursor to...).
(6.) At the end of the script, write the query results to Praat Info. Try to replicate the following output (heading informs about specified formant; round mean and sd to 2 decimal places):
Results for F1
mean = 455.54
standard deviation = 2.99
time of maximum: 16.000498865517002
Results for F2
mean = 1645.34
standard deviation = 3.94
time of maximum: 15.999669746744102
That's it, the script fits the job description formulated above. But certainly, there's room for improvements. First, the script is messy. Each time you run it, it generates two new objects which are of no interest to you. After the next session on object selection you'll know how to address this problem. Second, if you are interested in more than one formant, you have to edit the formant variable each time and run the script for each formant separately. This could be enhanced with the help of a loop (session 9). Third, if you need this (or a similar) analysis very often, you may want to list the script in the
Formant menu of the sound editor. Then, at the latest, you'll need a more convenient method to set the
maxFormant parameter. That's implemented with an input form (session 11).