# Given a textgrid, will extract a given instance of a word from that textgrid. # Created Jevon Heath 2014-4-7. form comment Target word text targetword Word integer Tier_to_extract 3 integer Iteration_to_use 3 endform iteration_to_use -= 1 ; This will choose the appropriate iteration tgold = selected("TextGrid") sdold = selected("Sound") sdold$ = selected$("Sound") select tgold totalits = do ("Count labels...", tier_to_extract, targetword$) ; make sure the word is in that tier if totalits = 0 exit Target word does not appear. endif select tgold plus sdold do ("Extract intervals where...", tier_to_extract, "yes", "is equal to", "'targetword$'") sdnew = selected("Sound") + iteration_to_use ; when multiple Sounds are selected, the first one is ; treated as "selected" select sdnew mnp = do ("To Manipulation...", 0.01, 75, 600) dur = do ("Extract duration tier") selectObject (sdnew) soundstart = do ("Get start time") soundend = do ("Get end time") # appendInfoLine(soundstart, " ", soundend) selectObject (tgold) tgnew = do("Extract part...", soundstart, soundend, "yes") t1 = Get start point... 1 2 ; If there's an error here, make sure the word starts at the right time t2 = Get end point... 1 2 durCurrent = t2 - t1 select dur do("Remove points between...", t1-0.1, t2+0.1) durNew = durCurrent * 2 Add point... 't1'-0.0001 1 Add point... 't1'+0.0001 2 Add point... 't2'-0.0001 2 Add point... 't2'+0.0001 1 select mnp plus dur Replace duration tier select mnp Get resynthesis (overlap-add) ; Cleanup select mnp do ("Remove") select dur do ("Remove") select tgnew do ("Remove") sdremove = sdnew - iteration_to_use for i from 1 to totalits select sdremove - 1 + i do ("Remove") endfor