# This script calculates the duration, pitch, intensity, and formants # Written by Setsuko Shirai # Ask a user to the directory, the name of a long file # and the maximum number of rows in the output EXCEL file # form supply arguments sentence input_directory C:\User Files\ssetsuko\run sentence output_directory C:\User Files\ssetsuko\run sentence target_text aa positive max_rows 100 positive prediction_order 9 positive minimum_pitch 75 positive maximum_pitch 500 positive new_sample_rate 11025 positive word_tier 2 positive darpabet_tier 4 positive style_tier 7 positive lombard_tier 8 endform # finding files we are looking for type_file$ = "Collection" Create Strings as file list... list 'input_directory$'\*.'type_file$' # the name of files - later we could track each file numberOfFiles = Get number of strings # To determine the name of table select Strings list fileName$ = Get string... 1 newLength = length (fileName$) - length (".Collection") newFileName$ = left$ (fileName$, newLength) tableName$ = newFileName$ + "vowels" Create Table... 'tableName$' 'max_rows' 25 Set column label (index)... 1 file_name Set column label (index)... 2 indices Set column label (index)... 3 word Set column label (index)... 4 vowel Set column label (index)... 5 style Set column label (index)... 6 noise Set column label (index)... 7 begin_time Set column label (index)... 8 end_time Set column label (index)... 9 duration Set column label (index)... 10 mean_intensity Set column label (index)... 11 max_intensity Set column label (index)... 12 max_int_time Set column label (index)... 13 min_intensity Set column label (index)... 14 min_int_time Set column label (index)... 15 mean_pitch Set column label (index)... 16 max_pitch Set column label (index)... 17 max_pit_time Set column label (index)... 18 min_pitch Set column label (index)... 19 min_pit_time Set column label (index)... 20 formant1 Set column label (index)... 21 formant2 Set column label (index)... 22 formant3 Set column label (index)... 23 form1mean Set column label (index)... 24 form2mean Set column label (index)... 25 form3mean counter = 0 for ifile to numberOfFiles select Strings list fileName$ = Get string... ifile Read from file... 'input_directory$'\'fileName$' # creating new file name without ".Collection" # If the filename$ is "a_1.Collection," # then the newFileName$ would # be "a_1" newLength = length (fileName$) - length (".Collection") newFileName$ = left$ (fileName$, newLength) temp$ = "temp" select Sound 'newFileName$' Rename... 'temp$' Resample... 'new_sample_rate' 50 Rename... 'newFileName$' select Sound 'temp$' Remove select Sound 'newFileName$' To Intensity... 100 0 select Sound 'newFileName$' # 1st argument: Time step (s), 2nd argument: Minimum pitch for Analysis, # 3rd argument: Maximum pitch for Analysis To Pitch... 0.01 'minimum_pitch' 'maximum_pitch' Rename... 'newFileName$' select Sound 'newFileName$' # 1st argument: prediction order, 2nd argument: Analysis width (seconds) # 3rd argument: Time step (seconds), 4th argument: Pre-emphasis from (Hz) To LPC (autocorrelation)... prediction_order 0.025 0.005 50 To Formant select LPC 'newFileName$' Remove select TextGrid 'newFileName$' numPhone = Get number of intervals... 'darpabet_tier' for iPhone to numPhone select TextGrid 'newFileName$' phone$ = Get label of interval... 'darpabet_tier' 'iPhone' target_text1$ = target_text$ + "1" target_text2$ = target_text$ + "2" target_text3$ = target_text$ + "3" target_text0$ = target_text$ + "0" if (phone$ = target_text$) or (phone$ = target_text0$) or (phone$ = target_text1$) or (phone$ = target_text2$) or (phone$ = target_text3$) counter = counter + 1 select TextGrid 'newFileName$' beginTime = Get starting point... 'darpabet_tier' 'iPhone' endTime = Get end point... 'darpabet_tier' 'iPhone' period = endTime - beginTime midTime = (beginTime + endTime) / 2 intervalNum = Get interval at time... 'word_tier' 'midTime' wText$ = Get label of interval... 'word_tier' 'intervalNum' styleNum = Get interval at time... 'style_tier' 'midTime' sText$ = Get label of interval... 'style_tier' 'styleNum' lombardNum = Get interval at time... 'lombard_tier' 'midTime' lText$ = Get label of interval... 'lombard_tier' 'lombardNum' select Intensity 'newFileName$' meanIntensity = Get mean... 'beginTime' 'endTime' minIntensity = Get minimum... 'beginTime' 'endTime' Parabolic minIntTime = Get time of minimum... 'beginTime' 'endTime' Parabolic maxIntensity = Get maximum... 'beginTime' 'endTime' Parabolic maxIntTime = Get time of maximum... 'beginTime' 'endTime' Parabolic minIntensity$ = fixed$ (minIntensity, 2) if minIntensity$ = "--undefined--" minIntensity$ = "0" endif maxIntensity$ = fixed$ (maxIntensity, 2) if maxIntensity$ = "--undefined--" maxIntensity$ = "0" endif minIntTime$ = fixed$ (minIntTime, 4) if minIntTime$ = "--undefined--" minIntTime$ = "0" endif maxIntTime$ = fixed$ (maxIntTime, 2) if maxIntTime$ = "--undefined--" maxIntTime$ = "0" endif select Pitch 'newFileName$' meanPitch = Get mean... 'beginTime' 'endTime' Hertz maxPitch = Get maximum... 'beginTime' 'endTime' Hertz Parabolic maxPitTime = Get time of maximum... 'beginTime' 'endTime' Hertz Parabolic minPitch = Get minimum... 'beginTime' 'endTime' Hertz Parabolic minPitTime = Get time of minimum... 'beginTime' 'endTime' Hertz Parabolic meanIntensity$ = fixed$ (meanIntensity, 2) if meanIntensity$ = "--undefined--" meanIntensity$ = "0" endif meanPitch$ = fixed$ (meanPitch, 2) if meanPitch$ = "--undefined--" meanPitch$ = "0" endif minPitch$ = fixed$ (minPitch, 2) if minPitch$ = "--undefined--" minPitch$ = "0" endif maxPitch$ = fixed$ (maxPitch, 2) if maxPitch$ = "--undefined--" maxPitch$ = "0" endif minPitTime$ = fixed$ (minPitTime, 4) if minPitTime$ = "--undefined--" minPitTime$ = "0" endif maxPitTime$ = fixed$ (maxPitTime, 2) if maxPitTime$ = "--undefined--" maxPitTime$ = "0" endif # from -5ms to +5ms midTb = midTime - 5 midTe = midTime + 5 select Formant 'newFileName$' f1 = Get value at time... 1 'midTime' Hertz Linear f2 = Get value at time... 2 'midTime' Hertz Linear f3 = Get value at time... 3 'midTime' Hertz Linear f1m = Get mean... 1 'beginTime' 'endTime' Hertz f2m = Get mean... 2 'beginTime' 'endTime' Hertz f3m = Get mean... 3 'beginTime' 'endTime' Hertz f1$ = fixed$ (f1, 2) if f1$ = "--undefined--" f1$ = "0" endif f2$ = fixed$ (f2, 2) if f2$ = "--undefined--" f2$ = "0" endif f3$ = fixed$ (f3, 2) if f3$ = "--undefined--" f3$ = "0" endif f1m$ = fixed$ (f1m, 2) if f1m$ = "--undefined--" f1m$ = "0" endif f2m$ = fixed$ (f2m, 2) if f2m$ = "--undefined--" f2m$ = "0" endif f3m$ = fixed$ (f3m, 2) if f3m$ = "--undefined--" f3m$ = "0" endif select Table 'tableName$' Set string value... counter file_name 'newFileName$' Set numeric value... counter indices 'counter' Set string value... counter word 'wText$' Set string value... counter style 'sText$' Set string value... counter noise 'lText$' Set string value... counter vowel 'phone$' # time Set numeric value... counter begin_time 'beginTime' Set numeric value... counter end_time 'endTime' Set numeric value... counter duration 'period' select Table 'tableName$' # intensity Set numeric value... counter mean_intensity 'meanIntensity$' Set numeric value... counter max_intensity 'maxIntensity$' Set numeric value... counter max_int_time 'maxIntTime' Set numeric value... counter min_intensity 'minIntensity$' Set numeric value... counter min_int_time 'minIntTime' # pitch Set numeric value... counter mean_pitch 'meanPitch$' Set numeric value... counter max_pitch 'maxPitch$' Set numeric value... counter max_pit_time 'maxPitTime$' Set numeric value... counter min_pitch 'minPitch$' Set numeric value... counter min_pit_time 'minPitTime$' # formant Set numeric value... counter formant1 'f1$' Set numeric value... counter formant2 'f2$' Set numeric value... counter formant3 'f3$' Set numeric value... counter form1mean 'f1m$' Set numeric value... counter form2mean 'f2m$' Set numeric value... counter form3mean 'f3m$' endif endfor select Formant 'newFileName$' Remove select Pitch 'newFileName$' Remove select Intensity 'newFileName$' Remove select Sound 'newFileName$' Remove select TextGrid 'newFileName$' Remove endfor select Table 'tableName$' newTableName$ = tableName$ + "_" + target_text$ Write to table file... 'output_directory$'\'newTableName$'.xls