# This script logs the starting point, end point, and duration # of labeled intervals in a specified interval tier # and/or the timepoint of labeled points in a specified point tier # for all files in a folder # # Author: Danielle Daidone 6/20/22 #################################################### form Get duration from labeled segments in files comment Directory of sound files and textgrids. Be sure to include the final slash. text directory C:/Users/Danielle/Desktop/Test/ comment Name of the output file with the measurements sentence results_file measurements comment Which INTERVAL tier do you want to analyze? Leave 0 if none. integer Int_tier 0 comment Which POINT tier do you want to analyze? Leave 0 if none. integer Point_tier 0 endform # Check if the result file exists: fileName$ = "'directory$''results_file$'.txt" if fileReadable (fileName$) pause The results file already exists! Do you want to overwrite it? filedelete 'fileName$' endif # Create a header row for the result file (remember to edit this if you add or change the analyses!) fileappend 'fileName$' SoundName, ...Tier,TextGridLabel, ...Start,End,Point,Duration ...'newline$' writeInfoLine: "SoundName, Tier, TextGridLabel, Start, End, Point, Duration" # Make a listing of all the sound files in a directory Create Strings as file list... list 'directory$'*.wav numberOfFiles = Get number of strings # Open each sound file in the directory for ifile to numberOfFiles filename$ = Get string... ifile Read from file... 'directory$''filename$' # Get the name of the sound object soundname$ = selected$ ("Sound", 1) # Look for a TextGrid by the same name gridfile$ = "'directory$''soundname$'.TextGrid" # If a TextGrid exists, open it and do the analysis if fileReadable (gridfile$) Read from file... 'gridfile$' select Sound 'soundname$' select TextGrid 'soundname$' # Run analyses on interval tier, if one exists if int_tier <> 0 numberOfIntervals = Get number of intervals... int_tier # Pass through all intervals in the designated tier, and if they have a label, do the analysis for interval to numberOfIntervals label$ = Get label of interval... int_tier interval if label$ <> "" # Get start and end points, duration start = Get starting point... int_tier interval end = Get end point... int_tier interval duration = end-start # Save result to text file resultline$ = "'soundname$','int_tier','label$','start','end',NA,'duration''newline$'" appendInfoLine: resultline$ fileappend 'fileName$' 'resultline$' # Select the TextGrid so we can iterate to the next interval select TextGrid 'soundname$' endif endfor endif # Remove the TextGrid select TextGrid 'soundname$' Remove endif # Remove the Sound object select Sound 'soundname$' Remove # and go on with the next sound file select Strings list endfor # Open each sound file in the directory for ifile to numberOfFiles filename$ = Get string... ifile Read from file... 'directory$''filename$' # Get the name of the sound object soundname$ = selected$ ("Sound", 1) # Look for a TextGrid by the same name gridfile$ = "'directory$''soundname$'.TextGrid" # If a TextGrid exists, open it and do the analysis if fileReadable (gridfile$) Read from file... 'gridfile$' select Sound 'soundname$' select TextGrid 'soundname$' # Run analyses on point tier, if one exists if point_tier <> 0 points = Get number of points... point_tier for point from 1 to points pointName$ = Get label of point... point_tier point if pointName$ <> "" # Get timepoint of point time = Get time of point... point_tier point # Save result to text file resultline$ = "'soundname$','point_tier','pointName$',NA,NA,'time',NA'newline$'" appendInfoLine: resultline$ fileappend 'fileName$' 'resultline$' # Select the TextGrid so we can iterate to the next interval select TextGrid 'soundname$' endif endfor endif # Remove the TextGrid select TextGrid 'soundname$' Remove endif # Remove the Sound object select Sound 'soundname$' Remove # and go on with the next sound file select Strings list endfor # When everything is done, clear the Objects window select all Remove