################################################################################################### # diphone.list-extracted.from.which.TextGrids.praat ( Written by Kyuchul Yoon kyoon@ling.osu.edu ) # This script lists the component diphones and their origins in terms of TextGrid files. # Given a textgrid with a diphones tier, it will extract its component diphones, and # query the origins of the diphones based on the file (also given) containing all the # actual existing diphones and their textgrid origins. # Given an unseen textgrid with a diphones tier, the output file will say whether the diphones # can be found (and where if found) or not (with a warning!) ################################################################################################### form Specify files and folders word inFolder lab.TextGrid.after.LTS.scheme.diphone.textgrid-after.execution natural diphoneTier 6 word inFileExt_(with_dot) .TextGrid.prosodic.diphone word diphoneList DIPHONES.and.their.TEXTGRID.NAMES-minimal-ALL.TXT comment outFolder will have an additional .OUT suffix word outFileExt_(with_dot) .diphone.textgrid-location endform # Create the output folder outFolder$ = inFolder$ + ".OUT" system mkdir 'outFolder$' # Read the diphoneList file Read Strings from raw text file... 'diphoneList$' Rename... diphoneList numDiphones = Get number of strings pause 'numDiphones' diphones identified. Continue? # Read the input file Create Strings as file list... fileList 'inFolder$'\*'inFileExt$' numFiles = Get number of strings pause 'numFiles' input files identified. Continue? # Loop through each file for iFile to numFiles select Strings fileList fileName$ = Get string... iFile tempName$ = fileName$ - inFileExt$ outFile$ = tempName$ + outFileExt$ Read from file... 'inFolder$'\'fileName$' Rename... textgrid numDiphoneTierIntervals = Get number of intervals... diphoneTier # Print the header line fileappend 'outFolder$'\'outFile$' interval#'tab$'diphone'tab$'diphoneTextGrid'tab$'diphoneTierInterval#'tab$'diphone#'newline$' ###################### # FOR EACH DIPHONE # Loop through each interval for iInterval from 2 to (numDiphoneTierIntervals-1) select TextGrid textgrid intervalText$ = Get label of interval... diphoneTier iInterval # Get the first file name and set the textgrid flag # Start from 2 for iDiphone because the first is the header line iDiphone = 2 flag = 1 fileFlag = 1 ####################################### # DIPHONE.LIST file (i.e., text output of # MARKED.DIPHONES TEXTGRIDS) SEARCHING ####################################### # Loop through each marked.diphones file to find the current diphone while (flag = 1 and iDiphone <= numDiphones) select Strings diphoneList diphoneLine$ = Get string... iDiphone indexOfTab = index(diphoneLine$, tab$) indexOfSpace = index(diphoneLine$, " ") stringBeforeSpace$ = left$(diphoneList$, (indexOfSpace-1)) lenStringBeforeSpace = length(stringBeforeSpace$) stringFileName$ = right$(stringBeforeSpace$, (lenStringBeforeSpace-indexOfTab)) diphoneCol$ = left$(diphoneLine$, (indexOfTab-1)) if diphoneCol$ = intervalText$ flag = 2 # If the current filename is the same as the origin of the diphone, # then let the user know it if stringFileName$ = fileName$ fileFlag = 2 endif endif iDiphone = iDiphone + 1 endwhile ##################### # FOUND IT !! # If the textgrid flag is changed, output the result if (flag = 2 and fileFlag = 2) fileappend 'outFolder$'\'outFile$' 'iInterval''tab$''diphoneLine$'******MYSELF!!!'newline$' elsif flag = 2 fileappend 'outFolder$'\'outFile$' 'iInterval''tab$''diphoneLine$''newline$' elsif flag = 1 fileappend 'outFolder$'\'outFile$' 'iInterval''tab$'N/A'newline$' endif endfor select TextGrid textgrid Remove endfor select Strings fileList plus Strings diphoneList Remove ############## END OF SCRIPT #################