You can refer to several attributes of objects that are visible in the List of Objects. To do so, use either the unique ID of the object, or the type and the name of the object. Thus,
object refers to the object that has the number 113 in the list, and
object["Sound hallo"] refers to an existing Sound object whose name is "hallo" (if there is more than one such object, it refers to the one that was created last).
To refer to an attribute, you use the period ("."). Thus,
object["Sound hallo"].nx is the number of samples of the Sound called hallo, and
1/object["Sound hallo"].dx is its sampling frequency.
Record a Sound (read the Intro if you do not know how to do that), and name it "mysound" (or anything else). An object with a name like "3. Sound mysound" will appear in the list. Then type into the calculator the formula
After you click OK, the Info window will show the number of samples. Since you could have got this result by simply selecting the object and choosing Get number of samples from the Query menu, these attribute tricks are not very useful in the calculator. We will see that they are much more useful in creation and modification formulas and in scripts.
The following attributes are available:
In formulas for creating a new object, you can refer to the attributes of any object, but you will often want to refer to the attributes of the object that is just being created. You can do that in two ways.
The first way is to use the name of the object, as above. Choose Create Sound from formula..., supply hello for its name, supply arbitrary values for the starting and finishing time, and type the following formula:
(x - object["Sound hello"].xmin) / (object["Sound hello"].xmax - object["Sound hello"].xmin)
When you edit this sound, you can see that it creates a straight line that rises from 0 to 1 within the time domain.
The formula above will also work if the Sound under creation is called goodbye, and a Sound called hello already exists; of course, in such a case
object["Sound hello"].xmax refers to a property of the already existing sound.
If a formula refers to an object under creation, there is a shorter way: you do not have to supply the name of the object at all, so you can simply write
(x - xmin) / (xmax - xmin)
The attributes that you can use in this implicit way are xmin, xmax, ncol, nrow, nx, dx, ny, and dy. To disambiguate in case there exists a script variable xmin as well (Praat will complain if this is the case), you can write
In formulas for modifying an existing object, you refer to attributes in the same way as in creation formulas, i.e., you do not have to specify the name of the object that is being modified. The formula
self * 20 ^ (- (x - xmin) / (xmax - xmin))
causes the sound to decay exponentially in such a way that it has only 5 percent of its initial amplitude at the end. If you apply this formula to multiple Sound objects at the same time,
xmax will refer to the finishing time of each Sound separately as that Sound is modified.
More examples of the use of attributes are on the next page.
© ppgb, June 14, 2017