##################################################################################### # TextGrid preparation script: Written by Kyuchul Yoon ( kyoon@ling.osu.edu ) # Help from Mary Beckman ( mbeckman@ling.osu.edu ) with inserting break index tier, etc. # Script should be in the parent directory where 30[23]00[024].txt/ folders belong. # Two subdirectories should be csplit-rom/ and TextGrids/. # The script assumes that you already have the romanized files for hangul sentences. # The romanized files should contain romanized eojeols that are "carriage-return"-separated. # The script will read in all the .rom files one by one from csplit-rom/ directory # and write default TextGrid files into TextGrids/ directory. # The filename of the output TextGrid files are ...rom.TextGrid ##################################################################################### # Eojeols in word tier will be placed in the right side of the TextGrid depending on the factorOfDistance # so that moving boundaries (Shift + Dragging) may be easy later on in another script # If factorOfDistance is 2, eojeols will be in the right half of TextGrid. If 3, in the right two thirds. If 5, in the right four fifths. # The variable factorOfDistance added for different screen resolutions. If your screen is smaller than 1024x768, 4 or bigger is good # Version2: Modified so that the last LHa gets replaced with L% # Version3: Modified so that existing .TextGrid files get overwritten with another execution of the script # Version4: Got rid of looping through all files in each of 30[23]00[024].txt/ folders because of the need to individually # adjust the factorOfDistance # The script assumes that you progress from the first to the next. This is so because the SoundEditor windows gets # the info on where to display from the immediately preceding TextGrid file. If no such file exists, it gives an error ##################################################################################### # Specify files and folders form Select files word longSoundFolder_(should_be_a_subfolder) 302000.txt word longSoundFile_(without_extension) 302000 word romFilesSubFolder csplit-rom word romFile_(without_extension) 302000-01 word textGridSubFolder TextGrid integer factorOfDistance 12 endform Open long sound file... 'longSoundFolder$'\'longSoundFile$'.wav # Get the end time that the script will use to display the appropriate section of the long sound file # First, get the two-digit number part of the .rom file romTwoDigit$ = right$(romFile$,2) romFirstDigit$ = left$(romTwoDigit$,1) romSecondDigit$ = right$(romTwoDigit$,1) # If the two-digit number is "01" then the end time is zero, otherwise, find the immediately previous TextGrid file # to figure out the ending time of the TextGrid, which corresponds to the end time of a previous utterance if romFirstDigit$ = "0" if romSecondDigit$ = "1" end = 0 else fileIndexToLoad = 'romSecondDigit$' - 1 Read from file... 'longSoundFolder$'\'textGridSubFolder$'\'longSoundFile$'-0'fileIndexToLoad'.TextGrid end = Get finishing time Remove endif else fileIndexToLoad = 'romTwoDigit$' - 1 Read from file... 'longSoundFolder$'\'textGridSubFolder$'\'longSoundFile$'-'fileIndexToLoad'.TextGrid end = Get finishing time Remove endif # Select the long sound file for identifying the start and end of an utterance select LongSound 'longSoundFile$' View editor LongSound 'longSoundFile$' roughUttDur = end + 40 Select... end roughUttDur Zoom to selection # Get start and end time of the section that you want to create TextGrid # for by prompting pause Pick the beginning of utterance start = Get cursor pause Pick the end of utterance end = Get cursor endeditor # Extract that part from the long sound Extract part... 'start' 'end' yes # Calculate the length of the extracted segment lengthSubPart = end - start Rename... subpart # Create a TextGrid for that subpart sound, remove the subpart sound To TextGrid... "word phonology phonetics break-index misc" phonology phonetics break-index # Sound "subpart" was just for creating a TextGrid file select Sound subpart Remove # Get the number of strings (newline-separated eojeols) and create interval tiers Read Strings from raw text file... 'longSoundFolder$'\'romFilesSubFolder$'\'romFile$'.rom Rename... rom numEojeols = Get number of strings # Insert an interval tier select TextGrid subpart for i from 1 to (numEojeols+1) # Place eojeols back by the factorOfDistance so moving points may be easy pseudoStart = start + lengthSubPart/factorOfDistance pseudoLengthSubPart = lengthSubPart * (1 - 1/factorOfDistance) nthBoundary = pseudoStart + (pseudoLengthSubPart/(numEojeols+2))*i Insert boundary... 1 'nthBoundary' endfor # and set texts for each interval numIntervals = Get number of intervals... 1 # The first and last interval will be Set interval text... 1 1 Set interval text... 1 numIntervals # Set the rest of the intervals for i from 2 to numIntervals-1 select Strings rom eojeolFromRom$ = Get string... 'i'-1 select TextGrid subpart Set interval text... 1 'i' 'eojeolFromRom$' endfor # Create as many tiers as you want: For break index numEojeols = numEojeols + 1 breakTime = Get end point... 1 1 Insert point... 4 breakTime # Loop through the eojeols in the word tier inserting a break index with BI value "2" after each one for i from 2 to numEojeols breakTime = Get end point... 1 i Insert point... 4 breakTime 2 endfor # For phonology tier for i from 2 to (numEojeols - 1) pointTime = Get end point... 1 i Insert point... 2 pointTime LHa endfor # The last boundary gets L% boundary tone pointTime = Get end point... 1 numEojeols Insert point... 2 pointTime L% # Save the TextGrid file select TextGrid subpart # If an old file exists, delete it first and then write filedelete 'longSoundFolder$'\'textGridSubFolder$'\'romFile$'.TextGrid Write to text file... 'longSoundFolder$'\'textGridSubFolder$'\'romFile$'.TextGrid # Select both the long sound and the TextGrid and present for verification select LongSound 'longSoundFile$' plus TextGrid subpart Edit # Waits for user verification pause Click OK if TextGrid looks fine # Remove current TextGrid and move on select TextGrid subpart Remove # Close the long sound file editor window select LongSound 'longSoundFile$' editor LongSound 'longSoundFile$' Close endeditor # clean up select Strings rom Remove select LongSound 'longSoundFile$' Remove ####### END OF SCRIPT #######