######################################################## # # NAME: msr_duration # # INPUT: - list of filenames; the filenames in the list don't have an extension. # - for each item in list: TextGrid with segmentation for nucleus (labeled # "n"). # # USAGE/COMMENTS: # This script extracts the durations of segments labeled "n" from a TextGrid # object and writes them to a textfile. The script is full of comments, # to make it suitable as a first acquaintance with Praat scripting. # # BY: Bert Remijsen # DATE: 03/09/2004 # ######################################################## # The section between 'form' and 'endform' places a window on the screen # via which the user can control the parameters of the script. form Measure durations comment Name of the text file with list of filenames (without its extension [.txt]): word listfile testlist1 comment inputlist and files are located in (directory): word inputdir U:\test comment The segments are located in tier number: integer tier_number 1 comment output gets written to (path and filename incl extension): word output U:\test\output_msrdur.txt endform # Read the list of files Read Strings from raw text file... 'inputdir$'\'listfile$'.txt end = Get number of strings # For each file in the list, the script carries out all the commands between # 'for' and 'endfor' for filecounter from 1 to end # assign the filename of the current item to a variable select Strings 'listfile$' file$ = Get string... filecounter # read the TextGrid file associated with this filename into Praat Read from file... 'inputdir$'\'file$'.TextGrid # This part of the script extracts the labels, start and end values # of the segments of interest from the TextGrid object. The values # are then used to determine the segment durations. nlabels = Get number of intervals... 'tier_number' for label from 1 to nlabels labelx$ = Get label of interval... tier_number label if (labelx$ = "n") nucleus_begin = Get starting point... tier_number label nucleus_end = Get end point... tier_number label nucleus_duration = nucleus_end - nucleus_begin endif endfor # The durational measurements are appended to a textfile. If the textfile # does not yet exist, it is created. echo 'file$' 'nucleus_duration' fappendinfo 'output$' # clean up - remove the TextGrid file select all minus Strings 'listfile$' Remove # end of the loop; if there are more items in the list of filenames the script # continues with the next item. endfor # end of the script; clean up of the list of filenames select Strings 'listfile$' Remove