################################################################ # TextGrid-former-w-after-LTS-texts.praat ( Written by Kyuchul Yoon kyoon@ling.osu.edu # This script forms TextGrids from raw text files composed of LTS output # Reads each raw text file and inserts each line one by one into the word interval tier of textgrids # reference textgrids will be used as place-holders for the raw text strings # original textgrids will be used for viewing original texts ################################################################ form Specify files and folders word inFolder_(with_raw_texts) lab.rawtext.after.LTS word inFileExt_(with_dot) .TextGrid word refTextGridFolder_(new_interval_to_be_inserted) lab.rawTextGrid.after.LTS word refTextGridExt_(with_dot) .TextGrid.done.lts word origTextGridFolder lab.TextGrid.before.LTS word origTextGridExt_(with_dot) .TextGrid.done word outFolder_(TextGrids_to_be_created_here) lab.TextGrid.after.LTS endform # Make a list of all .TextGrid filenames Create Strings as file list... fileList 'inFolder$'\*'inFileExt$' Sort Sort numFiles = Get number of strings pause 'numFiles' identified. Continue? # Loop through each file for iFile to numFiles select Strings fileList fileName$ = Get string... iFile filePrefix$ = fileName$ - inFileExt$ Read Strings from raw text file... 'inFolder$'\'fileName$' Rename... rawText numLines = Get number of strings # Read the reference TextGrid that will be inserted with new after.LTS interval texts Read from file... 'refTextGridFolder$'\'filePrefix$''refTextGridExt$' Rename... rawTextGrid Duplicate tier... 1 1 after.LTS numIntervals = Get number of intervals... 1 if (numLines-1) <> (numIntervals-2) pause numLines and numIntervals do not match!! endif # Read the original TextGrid from which original interval texts are to be copied to new textgrids Read from file... 'origTextGridFolder$'\'filePrefix$''origTextGridExt$' Rename... origTextGrid origNumIntervals = Get number of intervals... 1 if (numLines-1) <> (origNumIntervals-2) pause numLines and origNumIntervals do not match! endif # Insert another interval tier which will hold origTextGrid interval texts Duplicate tier... 1 1 before.LTS # For each line of the file for iLine from 2 to numLines select Strings rawText lineText$ = Get string... iLine select TextGrid origTextGrid origIntervalText$ = Get label of interval... 1 iLine select TextGrid rawTextGrid Set interval text... 2 iLine 'lineText$' Set interval text... 1 iLine 'origIntervalText$' endfor # Edit # pause Check before saving! Write to text file... 'outFolder$'\'fileName$' plus Strings rawText plus TextGrid origTextGrid Remove endfor select Strings fileList Remove ############# END OF SCRIPT ##############