# This script takes the set of TextGrid files in a folder # and get the durations of named intervals for each TextGrid files. # It writes all the interval measure of each file # per line in a tab-delimited text file. # This script is based on the script originally # written by Mietta Lennes, and revised by Shigeto Kawahara. # version 4/7/2009 # 19/01/2015 gedeeltelijk vertaald door Frits van Brenk # Here's an input form. form Calculate durations of labeled segments sentence Directory C:\ comment Welke tier van het TextGrid object wil je analyseren (standaard 1)? integer Tier 1 comment Waar wil je de resultaten opslaan? text textfile ddk_duur.txt endform # get the number of TextGrid files for looping # this should not be new. Create Strings as file list... list 'directory$'\*.TextGrid select Strings list ns = Get number of strings # start of the loop # now open one file at a time for i to ns select Strings list gridname$ = Get string... i Read from file... 'directory$'\'gridname$' endfor # get the name of each file # read it and select it for i to ns select Strings list gridname$ = Get string... i name$ = gridname$ - ".TextGrid" Read from file... 'directory$'\'gridname$' select TextGrid 'name$' fileappend "'textfile$'" 'name$''tab$' # check how many intervals there are in the selected tier. # I use the Praat function "Get number of intervals..." # and use the variable "tier" numberOfIntervals = Get number of intervals... tier # loop through all the intervals for interval from 1 to numberOfIntervals label$ = Get label of interval... tier interval # if the interval has some text as a label, # then calculate the duration. # "<>" means "not equal to" # So label$<>"" means "if the label is not empty" # You can of course say if label$="red", # then the script will analyze # all the intervals named "red" if label$ <> "" # OK, start is a numerical variable # Here, I use Praat's function "Get starting point" to # get the starting time of an interval. start = Get starting point... tier interval # end and duration are also variables end = Get end point... tier interval duration = end - start # append the label and the duration # to the end of the text file, # separated with a tab: resultline$ = "'duration''tab$'" fileappend "'textfile$'" 'resultline$' endif endfor #start a new line fileappend "'textfile$'" 'newline$' endfor select all minus Strings list Remove