Lines 51 and 53 both give a value to a string variable, one by directly giving a value in double quotes , and the other by using a function that reads a TextGrid label:. After a string variable has been defined, it can be used interchangeably with its value, i. Some functions expect strings to be entered directly, i. In this way, the function of single quotes is the opposite of the function of double quotes.
The Praat manual Help… Praat Intro contains a lot of information about things you can do with variables. Lines show some simple arithmetic with numeric variables. Forms are a convenient way of giving information to the script. When the script is run, the commands on lines will cause a window to open and prompt the user for the name of the sound file, the two formant tracking parameters:.
The first line indicates that this is a form, and specifies what text is to appear in the window. One of the valuable things about scripts is that we can repeat an action an arbitrarily large number of times. The device that allows us to repeat something as many times as necessary is the for loop. In the script, everything from line 28 to line 75 is inside a for loop.
To make a for loop, we need to define a starting point and an end point, and a numeric variable that will take each value in between. In this case, we are calling the numerical variable i , and it will count up from 2 until it gets to the number of the second-to-last interval in the first tier TextGrid because the variable intervals was defined on line The lines of code inside the loop will run once for every value that i takes.
An if statement is similar to a for loop. A for loop determines how many times, and for what values of a variable, the enclosed lines of code will execute. An if statement determines whether the enclosed lines of code will run at all. In the script, everything from line 33 to line 74 is inside an if statement:.
It is conventional to indent all the lines within a loop or if statement, to make the code more readable, but Praat ignores this for the purposes of loops and if statements, because it relies on commands like endfor and endif to know when they end. When objects such as sounds and textgrids are in the object list, they need to be selected in order to be used.
This is the same as clicking on the object in the list. Line 20 selects the sound so that it can be used to make a Formant object:.
When we are done with an object, we can select it and then remove it. This is especially useful in scripts that create thousands of small objects.
The last two lines of the script remove the Formant object that was created by the script:. This script assumes that the sound file and textgrid are already open. The reason we write Praat scripts instead of Python scripts or R scripts is that we want to use all the features of Praat that are useful for acoustic analysis.
Any command that can be executed by clicking a button in the object window or an item in a dropdown menu can be executed in a script. Line 21 does the same thing:. The five values that would have been entered in the window appear as arguments to the function in the script. In this case, we are using the default values for three arguments, and using two numeric variables that were defined using the form at the beginning of the script. The names of Praat functions are the same as the names that appear in the menus, and arguments to the functions appear in the same order as they appear in the window when you run the command manually.
This makes it easy to guess how to enter a function in a script. To make it even easier, Praat has the Paste history option that is available in the Script editor window. Pasting history will insert into your script every command you ran manually since you opened Praat or last clicked Clear history.
The script uses several Praat functions that are meant for querying TextGrids and TextGrid tiers available under Query — whenever you are selecting a TextGrid in the object list :. Commands for querying TextGrid tiers typically take two arguments. The first is the tier number, and the second is either an interval number or a time.
Other objects are queried in the same way. To get formant values in lines , we select the Formant object and then query it using the Get value at time… command, with four arguments which formant to measure, when to measure it, and two other parameters specific to formant measurements, which here are set to the defaults. When we run a script to make a large number of measurements, it is useful to output the measurements to a file.
Line 73 is the line that does this:. The fileappend command takes two arguments: the name of a file, and a text string to add to the end of that file. Arpabet is such an example for English. If not, you can create your own ASCII transcription system, but be sure to keep track of which characters stand for which sounds. A window will come up to ask you for the tier names and which tiers are point tiers. What tiers and how many tiers you need depends on what you want to study, but it is safe to start with just "word" and "phoneme".
Interval tiers are useful when you want to know where and how long a segment is. This will open both objects in the same window. Now that you have a TextGrid, you can start segmenting the file by adding boundaries to the interval and point tiers. To start segmentation, first zoom in to the part of the sound file you want to segment.
First, decide where the boundary should be. You can do this by listening to the sound and consulting the waveform or spectrogram.
To add a boundary, simply click the small circles on the tier where you want the boundary. Hold down your mouse key to move a boundary. You can move aligned boundaries on different tiers by also holding down the Shift key.
When studying vowels, one thing you might want to do is to label the F1 and F2 values. You can do this by making sure that "Show formants" is checked:. The red dots are formant tracks. Now you can add the formant values to the F1 and F2 tiers. Save frequently! This can be done in the TextGrid Editor window. Praat sometimes crashes, and you don't want to lose your hard work. You can edit sounds in Praat pretty much the same way you edit text.
After selecting a portion of the sound, you can cut, copy, and paste as you would text. In the Edit menu of Praat, there is also the option of Set selection to zero , which set the elected portion to silence.
You can also reverse the selected sound with Reverse selection. If you're working with multiple objects in Praat, you can choose to save all of them together as a binary file.
0コメント