Praat Script

The following is the Praat Script that I used to extract formants. This comes mostly from code bye Joey Stanley, cited in the citations, though I did add a feature to extract pitch and also to take the mean of a time interval rather than a midpoint for the formants.

writeInfoLine: "Extracting formants..."
# Extract the names of the Praat objects

thisSound$ = selected$("Sound")

thisTextGrid$ = selected$("TextGrid")
# Extract the number of intervals in the phoneme tier

select TextGrid 'thisTextGrid$'

numberOfPhonemes = Get number of intervals: 1  

appendInfoLine: "There are ", numberOfPhonemes, " intervals."
# Create the Formant Object

select Sound 'thisSound$'

To Formant (burg)... 0 5 5000 0.025 50
# Create the Pitch Object

select Sound 'thisSound$'

To Pitch: 0.0, 75, 600
# Create the output file and write the first line.

outputPath$ = "/Users/oliviaphillips/Desktop/ES25/Formant_csv_Files/P7BlendFormants.csv"

writeFileLine: "'outputPath$'", "time,phoneme,F0,F1,F2,F3"
# Loop through each interval on the phoneme tier.

for thisInterval from 1 to numberOfPhonemes   

#appendInfoLine: thisInterval
    # Get the label of the interval   

select TextGrid 'thisTextGrid$'   

thisPhoneme$ = Get label of interval: 1, thisInterval   

#appendInfoLine: thisPhoneme$    

if thisPhoneme$ <> ""   

# Find the midpoint.   

t0 = Get start point: 1, thisInterval   

t1   = Get end point:   1, thisInterval   

duration = t1-t0       

# Extract pitch measurements

select Pitch 'thisSound$'

f0 = Get mean: t0, t1, "Hertz"
# Extract formant measurements   

select Formant 'thisSound$'   

f1 = Get mean: 1, t0, t1, "Hertz"   

f2 = Get mean: 2, t0, t1, "Hertz"   

f3 = Get mean: 3, t0, t1, "Hertz"
    # Save to a spreadsheet   

appendFileLine: "'outputPath$'",                    

...t0, ",",                   

...thisPhoneme$, ",",                   

...f0, ",",                   

...f1, ",",                    

...f2, ",",                    

...f3 endif

endfor
appendInfoLine: newline$, newline$, "Whoo-hoo! It didn't crash!"