# This script segments a wav file and the TextGrid file that has the same name as the wav file # based on the sentence tier # Written by Setsuo Shirai # e-mail: ssetsuko@u.washington.edu # Ask a user to the directory and the name of a long file form supply arguments sentence input_directory C:\Praat\temp sentence output_directory C:\Praat\temp sentence fileName n1momfam.wav positive segment_tier 1 endform # Read long sound file Open long sound file... 'input_directory$'\'fileName$' # Finding the name of the TextGrid file newLength = length (fileName$) - length (".wav") originFileName$ = left$ (fileName$, newLength) # Read the textGrid file Read from file... 'input_directory$'\'originFileName$'.TextGrid # get the number of intervals numInterval = Get number of intervals... 'segment_tier' # counting the number of words totalNumWord = 0 # counting the number of sentences numberSentence = 0 for i to numInterval newFileName$ = originFileName$ + "_" + fixed$ (i, 0) select TextGrid 'originFileName$' sTime = Get starting point... 'segment_tier' i eTime = Get end point... 'segment_tier' i Extract part... sTime eTime yes Rename... 'newFileName$' # Check if this interval contains any text text$ = Get label of interval... 'segment_tier' 1 select LongSound 'originFileName$' Extract part... sTime eTime yes Rename... 'newFileName$' if length (text$) = 0 select TextGrid 'newFileName$' Remove select Sound 'newFileName$' Remove else if numberSentence = numberSentence +1 select TextGrid 'newFileName$' numWord = Get number of intervals... 2 totalNumWord = totalNumWord + numWord select TextGrid 'newFileName$' plus Sound 'newFileName$' Write to text file... 'output_directory$'\'newFileName$'.Collection select TextGrid 'newFileName$' Remove select Sound 'newFileName$' Remove endif endfor