This chapter handles the way you use white space, comments, and continuation lines in a Praat script.
Praat ignores all white space (spaces and tabs) that you put at the beginning of lines. The indentation that you saw on the previous page was therefore used solely for readability. You are advised to use indenting, though, with three or four spaces for each level, as in the following example, which loops over all tiers and intervals of a TextGrid:
writeInfoLine: "The texts in all tiers and intervals:"
numberOfTiers = Get number of tiers
for tierNumber from 1 to numberOfTiers
numberOfIntervals = Get number of intervals: tierNumber
for intervalNumber from 1 to numberOfIntervals
text$ = Get label of interval: tierNumber, intervalNumber
appendInfoLine: "Tier ", tierNumber, ", interval ", intervalNumber, ": ", text$
Praat also ignores lines that are empty or consist solely of white space, so you use those to structure your script visually.
Comments are lines that start with "#" or ";". Praat ignores these lines when your script is running:
# Create 1 second of a sine wave with a frequency of 100 Hertz,
# sampled at 44100 Hz:
Create Sound from formula: "sine", 1, 0, 1, 44100, ~ sin (2*pi*100*x)
Because of its visibility, you are advised to use "#" for comments that structure your script, and ";" perhaps only for "commenting out" a statement, i.e. to temporarily put it before a line that you don't want to execute.
There is normally one line per statement, and one statement per line. But some statements are very long, such as this one on a previous page:
appendInfoLine: "Interval ", intervalNumber, " is ", duration, " seconds long and contains the text: ", text$
By making the current window wider, you can see that I really put this whole statement on a single line. I could have distributed it over two lines in the following way, by using three dots (an ellipsis):
appendInfoLine: "Interval ", intervalNumber, " is ", duration, " seconds long
... and contains the text: ", text$
Here is another common type of example:
Create Sound from formula: "windowedSine", 1, 0, 1, 44100,
... ~ 0.5 * sin(2*pi*1000*x) * exp(-0.5*((x-0.5)/0.1)^2)
You will normally want to follow such an ellipsis with a space, unless you want to concatenate the parts of a long word:
Select outer viewport: 0, 10, 0, 4
Text top: "yes", "It's a long way to Llanfairpwllgwyngyll
... unless you start from Tyddyn-y-felin."
© ppgb, September 4, 2017