##get measurements.praat ##original script created by Christan Kroos, Rikke Bundgaard-Nielsen, Michael Tyler ##modified by Mark Antoniou ## C 2010 MARCS Auditory Laboratories # =============================================================== # 1. Because of a bug in Praat 'Show intensity' cannot be scripted. # Open an editor on an abritrary sound and make sure that 'Show intensity' is ticked before you run this script # 2. The comma-separated file is a .txt file. Import this into Excel and use the text import wizard to change columns to text format where necessary. # ================================================================ #create list of filenames clearinfo form Parameters comment Directory that contains the original stimuli sentence inDirectory /Users/zqi/Dropbox/BILD/MMN/experiment/Stimuli/normalized/da_s sentence filetype wav comment Name of the output csv file with the measurements sentence outFile measurements choice speaker_gender: 1 button Female button Male endform Create Strings as file list... fileList 'inDirectory$'/*.TextGrid fileappend 'inDirectory$'/'outFile$'.txt sound name, ...segment,start,end,duration,overall_dB,overall_f0, ...25_cursor,25_dB,25_f0,25_F1,25_F2,25_F3, ...50_cursor,50_dB,50_f0,50_F1,50_F2,50_F3, ...75_cursor,75_dB,75_f0,75_F1,75_F2,75_F3, ...'newline$' #loop for all files nFiles = Get number of strings for d from 1 to nFiles #read in sound file (aif) 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... 1 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 select Sound 'soundName$' To Pitch... 0.01 75 600 select Sound 'soundName$' To Intensity... 100 0 yes for s from 1 to 'number_of_intervals' select TextGrid 'soundName$' segment$ = Get label of interval... 1 s if segment$ <> "" startSeg = Get starting point... 1 s endSeg = Get end point... 1 s durSeg = 'endSeg' - 'startSeg' cursor_25 = 'startSeg' + ('durSeg' * 0.25) cursor_50 = 'startSeg' + ('durSeg' * 0.5) cursor_75 = 'startSeg' + ('durSeg' * 0.75) select Intensity 'soundName$' overall_dB = Get mean... 'startSeg' 'endSeg' dB dB_25 = Get value at time... 'cursor_25' Cubic dB_50 = Get value at time... 'cursor_50' Cubic dB_75 = Get value at time... 'cursor_75' Cubic if segment$ == "ba" or segment$ == "da" select Pitch 'soundName$' overall_f0 = Get mean... 'startSeg' 'endSeg' Hertz f0_25 = Get value at time... 'cursor_25' Hertz Linear f0_50 = Get value at time... 'cursor_50' Hertz Linear f0_75 = Get value at time... 'cursor_75' Hertz Linear select Formant 'soundName$' 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 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 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 fileappend 'inDirectory$'/'outFile$'.txt 'soundName$', ...'segment$','startSeg','endSeg','durSeg', ...'overall_dB','overall_f0', ...'cursor_25','dB_25','f0_25','f1_25','f2_25','f3_25', ...'cursor_50','dB_50','f0_50','f1_50','f2_50','f3_50', ...'cursor_75','dB_75','f0_75','f1_75','f2_75','f3_75', ...'newline$' else fileappend 'inDirectory$'/'outFile$'.txt 'soundName$', ...'segment$','startSeg','endSeg','durSeg', ...'overall_dB',, ...'cursor_25','dB_25',,,,, ...'cursor_50','dB_50',,,,, ...'cursor_75','dB_75',,,,, ...'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$' fileappend 'inDirectory$'/'outFile$'.txt Processed all files in 'inDirectory$'