# Pull out relevant words found in text file and put on additional tier # # 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 3/16/22 #################################################### form Add relevant words to additional tier comment Give the directory of the sound files and textgrids: sentence inputDir C:\Users\daidoned\Desktop\Test\ comment Give the name of the input text file with relevant words: word inputTable C:\Users\daidoned\Desktop\Test\words_simple.txt comment Which tier in the TextGrid contains the words you want to copy? integer Tier 1 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 # get current number of tiers nbTiers = Get number of tiers # add new tier at the bottom newTier = nbTiers + 1 Insert interval tier... newTier words # 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, insert boundaries in bottom tier at same time points # ignores the error if a boundary is already present from the previous word select TextGrid textgrid start = Get start point... tier interval end = Get end point... tier interval nocheck Insert boundary... newTier start nocheck Insert boundary... newTier end # label interval in bottom tier with word intervalNb = Get interval at time... newTier start Set interval text... newTier intervalNb 'intname$' endif endfor endfor #save modified textgrid select TextGrid textgrid Save as text file... 'inputDir$'Updated/'textgridFile$' appendInfoLine: "updated 'textgridFile$'" endfor select all Remove