#Segments non-null labelled intervals in tier 1 of TextGrids. #@author: Stephanie Packard # University of Iowa # 01/12/07 #IMPORTANT NOTES: #If you are segmenting files that are currently open in Praat, the sound file must be opened as a long sound file. #If you are writing files to the 'segments' folder, make sure that it actually exists. #This script does not assume that the sound files and textGrid files have the same file name, BUT make sure that they # are in the same order. #Additional sound file types can be implemented by adding buttons to the form and an elif to write the file (see comment below). form Script preferences choice WhichFiles: 1 button All files in current folder button File currently open in Praat choice FileType: 1 button .AIFF button .wav choice SaveWhere: 1 button Current folder button Subdirectory ('segments') choice SegmentName: 1 button Use label only button Add to label (see script) choice SaveAs: 1 button .AIFF button .wav endform searchType$ = "*" + "'fileType$'" if whichFiles = 1 Create Strings as file list... soundList 'searchType$' numSounds = Get number of strings if numSounds = 0 echo "There are no 'fileType$' sound files in the current directory." exit endif Create Strings as file list... gridList *.TextGrid numGrids = Get number of strings if numGrids = 0 echo "There are no TextGrid files in the current directory." exit endif assert numSounds = numGrids numFiles = numSounds for ifile to numFiles select Strings soundList soundName$ = Get string... ifile Open long sound file... 'soundName$' select Strings gridList gridName$ = Get string... ifile Read from file... 'gridName$' call segment endfor elif whichFiles = 2 call segment endif select all Remove procedure segment select all soundFile_name$ = selected$("LongSound") textGrid_name$ = selected$("TextGrid") select TextGrid 'textGrid_name$' num_of_intervals = Get number of intervals... 1 for i from 1 to num_of_intervals select TextGrid 'textGrid_name$' label$ = Get label of interval... 1 'i' if label$ <> "" beg = Get starting point... 1 'i' end = Get end point... 1 'i' select LongSound 'soundFile_name$' Extract part... beg end no if segmentName = 2 # CHANGE THE FOLLOWING LINE TO ADD TO THE SEGMENT FILE NAME addition$ = left$("'soundFile_name$'", 9) label$ = "'label$'" + "_" + "'addition$'" endif if saveWhere = 2 label$ = "segments/" + "'label$'" endif label$ = "'label$'" + "'saveAs$'" if saveAs$ = ".AIFF" Write to AIFF file... 'label$' elif saveAs$ = ".wav" Write to WAV file... 'label$' # ADD ELIF HERE TO IMPLEMENT ADDITIONAL SOUND FILE TYPES else echo "There is no code to write to 'saveAs$' file in the script." endif Remove endif endfor select LongSound 'soundFile_name$' plus TextGrid 'textGrid_name$' Remove endproc