##original script (get_measurements.praat) created by Christan Kroos, Rikke Bundgaard-Nielsen, Michael Tyler ##modified by Mark Antoniou ## C 2010 MARCS Auditory Laboratories # Modified by Danielle Daidone 3/3/18 to output text file with F1-F4 from specified tier of all sound files in a folder # **Textgrids should have same name as their corresponding sound file** ######################################################################################################################## form Parameters comment Folder that contains the sound files and textgrids sentence inDirectory C:\Users\Danielle\Desktop\Test\ sentence filetype wav comment Which tier do you want to process? integer tier 1 comment Name of the output text file with the measurements sentence outFile measurements comment Folder where you want to save the output file sentence outDirectory C:\Users\Danielle\Desktop\Test\ choice speaker_gender: 1 button Female button Male endform clearinfo #create list of filenames Create Strings as file list... fileList 'inDirectory$'*.TextGrid #check if the output file exists outputfile$ = outDirectory$ + outFile$ + ".txt" if fileReadable (outputfile$) pause The file 'outFile$'.txt already exists! Do you want to overwrite it? filedelete 'outputfile$' endif #write column labels to output text file fileappend 'outDirectory$''outFile$'.txt sound name, ...segment,start,end,duration, ...25_cursor,25_F1,25_F2,25_F3,25_F4, ...37.5_cursor,37.5_F1,37.5_F2,37.5_F3,37.5_F4, ...50_cursor,50_F1,50_F2,50_F3,50_F4, ...62.5_cursor,62.5_F1,62.5_F2,62.5_F3,62.5_F4, ...75_cursor,75_F1,75_F2,75_F3,75_F4, ...87.5_cursor,87.5_F1,87.5_F2,87.5_F3,87.5_F4, ...100_cursor,100_F1,100_F2,100_F3,100_F4 ...'newline$' #loop for all files nFiles = Get number of strings for d from 1 to nFiles #read in sound file and textgrid select Strings fileList fileName$ = Get string... d dotInd = rindex(fileName$, ".") soundName$ = left$(fileName$, dotInd - 1) printline Processing file 'soundName$'... Read from file... 'inDirectory$''soundName$'.'filetype$' Read from file... 'inDirectory$''soundName$'.Textgrid #Get relevant information from the textgrid (exclude non-labeled segments) and do measurements select TextGrid 'soundName$' number_of_intervals = Get number of intervals... tier select Sound 'soundName$' if speaker_gender$ == "Female" To Formant (burg)... 0.0025 5 5500 0.025 50 else To Formant (burg)... 0.0025 5 5000 0.025 50 endif #get time points for each measurement point within an interval for s from 1 to 'number_of_intervals' select TextGrid 'soundName$' segment$ = Get label of interval... tier s if segment$ <> "" startSeg = Get starting point... tier s endSeg = Get end point... tier s durSeg = 'endSeg' - 'startSeg' cursor_25 = 'startSeg' + ('durSeg' * 0.25) cursor_37_5 = 'startSeg' + ('durSeg' * 0.375) cursor_50 = 'startSeg' + ('durSeg' * 0.5) cursor_62_5 = 'startSeg' + ('durSeg' * 0.625) cursor_75 = 'startSeg' + ('durSeg' * 0.75) cursor_87_5 = 'startSeg' + ('durSeg' * 0.875) select Formant 'soundName$' #get F1-F4 values at 25% point f1_25 = Get value at time... 1 'cursor_25' Hertz Linear f2_25 = Get value at time... 2 'cursor_25' Hertz Linear f3_25 = Get value at time... 3 'cursor_25' Hertz Linear f4_25 = Get value at time... 4 'cursor_25' Hertz Linear #get F1-F4 values at 37.5% point f1_37_5 = Get value at time... 1 'cursor_37_5' Hertz Linear f2_37_5 = Get value at time... 2 'cursor_37_5' Hertz Linear f3_37_5 = Get value at time... 3 'cursor_37_5' Hertz Linear f4_37_5 = Get value at time... 4 'cursor_37_5' Hertz Linear #get F1-F4 values at 50% point f1_50 = Get value at time... 1 'cursor_50' Hertz Linear f2_50 = Get value at time... 2 'cursor_50' Hertz Linear f3_50 = Get value at time... 3 'cursor_50' Hertz Linear f4_50 = Get value at time... 4 'cursor_50' Hertz Linear #get F1-F4 values at 62.5% point f1_62_5 = Get value at time... 1 'cursor_62_5' Hertz Linear f2_62_5 = Get value at time... 2 'cursor_62_5' Hertz Linear f3_62_5 = Get value at time... 3 'cursor_62_5' Hertz Linear f4_62_5 = Get value at time... 4 'cursor_62_5' Hertz Linear #get F1-F4 values at 75% point f1_75 = Get value at time... 1 'cursor_75' Hertz Linear f2_75 = Get value at time... 2 'cursor_75' Hertz Linear f3_75 = Get value at time... 3 'cursor_75' Hertz Linear f4_75 = Get value at time... 4 'cursor_75' Hertz Linear #get F1-F4 values at 87.5% point f1_87_5 = Get value at time... 1 'cursor_87_5' Hertz Linear f2_87_5 = Get value at time... 2 'cursor_87_5' Hertz Linear f3_87_5 = Get value at time... 3 'cursor_87_5' Hertz Linear f4_87_5 = Get value at time... 4 'cursor_87_5' Hertz Linear #get F1-F4 values at 100% point (i.e. at right interval boundary) f1_100 = Get value at time... 1 'endSeg' Hertz Linear f2_100 = Get value at time... 2 'endSeg' Hertz Linear f3_100 = Get value at time... 3 'endSeg' Hertz Linear f4_100 = Get value at time... 4 'endSeg' Hertz Linear #write measurements to text file fileappend 'outDirectory$''outFile$'.txt 'soundName$', ...'segment$','startSeg','endSeg','durSeg', ...'cursor_25','f1_25','f2_25','f3_25','f4_25', ...'cursor_37_5','f1_37_5','f2_37_5','f3_37_5','f4_37_5', ...'cursor_50','f1_50','f2_50','f3_50','f4_50', ...'cursor_62_5','f1_62_5','f2_62_5','f3_62_5','f4_62_5', ...'cursor_75','f1_75','f2_75','f3_75','f4_75', ...'cursor_87_5','f1_87_5','f2_87_5','f3_87_5','f4_87_5', ...'endSeg','f1_100','f2_100','f3_100','f4_100', ...'newline$' endif endif endfor #clean object list select all minus Strings fileList Remove endfor #clean object list select all Remove printline -------------------------------- printline Processed all 'filetype$' files in 'inDirectory$'