# Identify words in a tier from a text file and replace corresponding interval label on other specified tier # For all files in a folder # # Put all of your relevant words in a single column in a text file # **Table must have header row, although name is irrelevant** # # ***Make sure you don't have any spaces in your file paths*** # (i.e. don't use folders with spaces in the name, and make sure there are no extra spaces at the end) # # # Author: Danielle Daidone 6/10/22 #################################################### form Add relevant words to additional tier comment Give the directory of the sound files and textgrids: sentence inputDir C:\Users\Danielle\Desktop\Test\ comment Give the name of the input text file with relevant words to be replaced: word inputTable C:\Users\Danielle\Desktop\Test\fillers.txt comment Which tier contains the words you are searching for? integer Tier 1 comment In which tier do you want the label to be replaced? integer Tier_rep 6 comment What should the replacement label be? sentence Rep_label sil endform createDirectory: "'inputDir$'\Updated" # remove any objects open in object window select all numberOfSelectedObjects = numberOfSelected () if numberOfSelectedObjects > 0 Remove endif # clear info window clearinfo # find TextGrid files in folder Create Strings as file list... list 'inputDir$'\*.TextGrid numberOfFiles = Get number of strings # go through each TextGrid for ifile to numberOfFiles select Strings list textgridFile$ = Get string... ifile Read from file... 'inputDir$''textgridFile$' Rename... textgrid # go through each interval in tier where the words are located numberOfIntervals = Get number of intervals... tier for interval from 1 to numberOfIntervals select TextGrid textgrid intname$ = Get label of interval... tier interval # read in table of relevant words; first row will be treated as headers Read Table from tab-separated file... 'inputTable$' Rename... table select Table table # get number of rows in table numRows = Get number of rows # for each row in the table for i to numRows # get name of word word$ = Table_table$ [i, 1] # check if label of interval matches that word from table if intname$ = word$ # if it does match, get interval information select TextGrid textgrid start = Get start point... tier interval # replace interval label in specified tier intervalNb = Get interval at time... tier_rep start Set interval text... tier_rep intervalNb 'rep_label$' endif endfor endfor #save modified textgrid select TextGrid textgrid Save as text file... 'inputDir$'Updated/'textgridFile$' appendInfoLine: "updated 'textgridFile$'" endfor select all Remove