# This script measures duration and formants of a vowel. # This program reads all Collection files in a directory. # Each Collection file consists of a Sound file plus a TextGrid # The names of a Collection file, the corresponding Sound file # and the corresponding TextGrid file should be the same. # For example, "cat.Collection" consists of "cat.Sound" plus "cat.TextGrid". # A user gives the position of target vowel # such as first Tier and second interval # Written by Setsuko Shirai # Contact ssetsuko@u.washington.edu # ask a user the directories form supply_arguments sentence input_directory C:\Praat\try sentence output_directory C:\Praat\try sentence type_file Collection positive tier_number 1 positive interval_number 2 endform # finding files we are looking for Create Strings as file list... list 'input_directory$'\*.'type_file$' # the name of files - later we could track each file Write to text file... 'output_directory$'\names.Strings numberOfFiles = Get number of strings for ifile to numberOfFiles select Strings list fileName$ = Get string... ifile Read from file... 'input_directory$'\'fileName$' endfor select all # Find the number of selected TextGrid files numSelected = numberOfSelected ("TextGrid") Create Table... durF1F2 numSelected 13 Set column label (index)... 1 nameFile Set column label (index)... 2 ipa Set column label (index)... 3 dur Set column label (index)... 4 f1_0 Set column label (index)... 5 f2_0 Set column label (index)... 6 f1_1 Set column label (index)... 7 f2_1 Set column label (index)... 8 f1_2 Set column label (index)... 9 f2_2 Set column label (index)... 10 f1_3 Set column label (index)... 11 f2_3 Set column label (index)... 12 f1_4 Set column label (index)... 13 f2_4 # calculate formants of each vowel for i to numSelected select all fileName$ = selected$("Sound", i) # The finding the ending point select TextGrid 'fileName$' pointS = Get starting point... tier_number interval_number pointE = Get end point... tier_number interval_number # Get the transcription of a phone text$ = Get label of interval... tier_number interval_number point = pointE - pointS # In order to track formants, # the program calculates formants at the beginning of the vowel, 1/4 # 1/2, 3/4 and the end of the vowel deltaTime = point / 4 point$ = fixed$ (point, 5) select Table durF1F2 Set string value... i nameFile 'fileName$' Set string value... i ipa 'text$' Set numeric value... i dur 'point' select Sound 'fileName$' # 1st argument: Time step (s), 2nd argument: Max. number of formants # 3rd argument: Maximum formant (Hx), 4th argument: Window length (s) # 5th argument: Pre-emphasis from (Hz) To Formant (burg)... 0.01 5 5500 0.025 50 time = pointS select Formant 'fileName$' f1 = Get value at time... 1 'time' Hertz Linear f2 = Get value at time... 2 'time' Hertz Linear f1$ = fixed$ (f1, 2) if f1$ = "--undefined--" f1$ = "0" endif f2$ = fixed$ (f2, 2) if f2$ = "--undefined--" f2$ = "0" endif select Table durF1F2 Set numeric value... i f1_0 'f1$' Set numeric value... i f2_0 'f2$' time = time + deltaTime select Formant 'fileName$' f1 = Get value at time... 1 'time' Hertz Linear f2 = Get value at time... 2 'time' Hertz Linear f1$ = fixed$ (f1, 2) if f1$ = "--undefined--" f1$ = "0" endif f2$ = fixed$ (f2, 2) if f2$ = "--undefined--" f2$ = "0" endif f2$ = fixed$ (f2, 2) if f2$ = "--undefined--" f2$ = "0" endif select Table durF1F2 Set numeric value... i f1_1 'f1$' Set numeric value... i f2_1 'f2$' time = time + deltaTime select Formant 'fileName$' f1 = Get value at time... 1 'time' Hertz Linear f2 = Get value at time... 2 'time' Hertz Linear f1$ = fixed$ (f1, 2) if f1$ = "--undefined--" f1$ = "0" endif f2$ = fixed$ (f2, 2) if f2$ = "--undefined--" f2$ = "0" endif select Table durF1F2 Set numeric value... i f1_2 'f1$' Set numeric value... i f2_2 'f2$' time = time + deltaTime select Formant 'fileName$' f1 = Get value at time... 1 'time' Hertz Linear f2 = Get value at time... 2 'time' Hertz Linear f1$ = fixed$ (f1, 2) if f1$ = "--undefined--" f1$ = "0" endif f2$ = fixed$ (f2, 2) if f2$ = "--undefined--" f2$ = "0" endif select Table durF1F2 Set numeric value... i f1_3 'f1$' Set numeric value... i f2_3 'f2$' time = time + deltaTime select Formant 'fileName$' f1 = Get value at time... 1 'time' Hertz Linear f2 = Get value at time... 2 'time' Hertz Linear f1$ = fixed$ (f1, 2) if f1$ = "--undefined--" f1$ = "0" endif f2$ = fixed$ (f2, 2) if f2$ = "--undefined--" f2$ = "0" endif select Table durF1F2 Set numeric value... i f1_4 'f1$' Set numeric value... i f2_4 'f2$' endfor select Table durF1F2 Write to table file... 'output_directory$'\durF1F2.xls