######################################################## # # ORIGINAL NAME: msr&check_f1f2_indiv_point.psc # # INPUT: - soundfile (samplingfreq above 16000 kHz) # - TextGrid with segmentation for vowel(s) # USAGE: # This script calculates F1 and F2 at each point on a tier in a TextGrid # file. The label of the point - if any - is not taken into account. # F1 and F2 are calculated using 'To formant (burg)' and # and the tracker. Both of these algorithms set parameters # as a function of speaker sex. This parameter is controlled # by the user. The Picture window shows the spectrogram and # formant tracks (F1 & F2), and The rounded F1 and F2 values # appear at the top. # As a additional check, and for voice quality measurements, # the script displays the spectrum, the Long-term average # spectrum (Ltas) and the LPC spectrum at the bottom. The # LPC spectrum at the bottom uses the 'autocorrelation' # algorithm, which is differen from the 'burg' algorithm # by means of which the values at the top are computed. # When the 'To formant' and 'Track...' procedures do not # produce plausible values, the user can (1) run the # script again with new tracking values, (2) on the basis # of the spectrum/Ltas/LPC display at the bottom part of # the Picture window, determine F1 and F2 by hand using # the Spectrum/Ltas/LPC in the Object window. # # The script can be modified to produce measurements on voice # quality with a check. # # BY: Bert Remijsen # DATE: 28/09/2004 # # CHANGED: Sven Grawunder # DATE: 25/08/2006 # ######################################################## form Calculate F1 & F2 for each point comment See header of script for details. comment measure point tier & token interval tier in the TextGrid: integer p_tier 3 integer int_tier 1 sentence Output_directory K:\didei\ word Data_file FormantTable17.txt comment Select sex of speaker: optionmenu sex 1 option male option female comment Length of window over which spectrogram is calculated: positive length 0.005 comment Play sound? Check Sonogramm/Spec/LTAS/LPC? choice playit 2 button yes button no choice checkit 2 button yes button no choice pitchobject 1 button yes button no comment Settings for Track... algorithm (MALE on the left; FEMALE on the right) positive left_F1_reference 500 positive right_F1_reference 550 positive left_F2_reference 1485 positive right_F2_reference 1650 positive left_F3_reference 2475 positive right_F3_reference 2750 positive left_Frequency_cost 1 positive right_Frequency_cost 1 positive left_Bandwidth_cost 1 positive right_Bandwidth_cost 1 positive left_Transition_cost 1 positive right_Transition_cost 1 endform spreadsheet$ = "'output_directory$''data_file$'" fileappend 'spreadsheet$' index'tab$'int_nr'tab$'token'tab$'pointtime'tab$'vowel_label'tab$'f0'tab$'f1'tab$'f2'tab$'f3'tab$'f1B'tab$'f2B'tab$'f3B'newline$' clearinfo counter = 0 name$ = selected$ ("Sound") sound = selected("Sound") textgrid = selected("TextGrid") if 'pitchobject'=2 select 'sound' To Pitch (cc)... 0 75 15 yes 0.03 0.45 0.01 0.35 0.14 300 endif #select 'sound' #Resample... 16000 50 select 'textgrid' finishing_time = Get finishing time npoints = Get number of points... 'p_tier' #for point from 1 to 'npoints' for point from 1 to 3 select 'textgrid' point_t = Get time of point... 'p_tier' 'point' point_l$ = Get label of point... 'p_tier' 'point' int_nr = Get interval at time... 'int_tier' 'point_t' token$ = Get label of interval... 'int_tier' 'int_nr' counter = counter + 1 select Pitch 'name$' f0 = Get quantile... 'point'-0.015 'point_t'+0.015 0.5 Hertz call vowelq 'point_t' 'name$' select 'textgrid' plus 'sound' endfor procedure vowelq point_t name$ # set maximum frequency of Formant calculation algorithm on basis of sex # sex is 1 for male (left); sex is 2 for remale (right). if 'sex' = 1 maxf = 5000 f1ref = left_F1_reference f2ref = left_F2_reference f3ref = left_F3_reference f4ref = 3465 f5ref = 4455 freqcost = left_Frequency_cost bwcost = left_Bandwidth_cost transcost = left_Transition_cost endif if 'sex' = 2 maxf = 5500 f1ref = right_F1_reference f2ref = right_F2_reference f3ref = right_F3_reference f4ref = 3850 f5ref = 4950 freqcost = right_Frequency_cost bwcost = right_Bandwidth_cost transcost = right_Transition_cost endif select Sound 'name$'_16000 # Resample... 16000 50 sound_16khz = selected("Sound") To Formant (burg)... 0.01 5 'maxf' 0.025 50 Rename... 'name$'_beforetracking formant_beforetracking = selected("Formant") Track... 3 'f1ref' 'f2ref' 'f3ref' 'f4ref' 'f5ref' 'freqcost' 'bwcost' 'transcost' Rename... 'name$'_aftertracking formant_aftertracking = selected("Formant") # Get the f1,f2,f3 measurements. select 'formant_aftertracking' f1hzpt = Get value at time... 1 'point_t' Hertz Linear f2hzpt = Get value at time... 2 'point_t' Hertz Linear f3hzpt = Get value at time... 3 'point_t' Hertz Linear f1bkpt = Get value at time... 1 'point_t' Bark Linear f2bkpt = Get value at time... 2 'point_t' Bark Linear f3bkpt = Get value at time... 3 'point_t' Bark Linear if (checkit = 1) # display the formant tracks overlaid on spectrogram. Erase all Font size... 14 display_from = 'point_t' - 0.15 if ('display_from' < 0) display_from = 0 endif display_until = 'point_t' + 0.15 if ('display_until' > 'finishing_time') display_until = 'finishing_time' endif select 'sound' To Spectrogram... 'length' 4000 0.002 20 Gaussian spectrogram = selected("Spectrogram") Viewport... 0 7 0 3.5 Paint... 'display_from' 'display_until' 0 4000 100 yes 50 6 0 no select 'formant_aftertracking' Yellow Speckle... 'display_from' 'display_until' 4000 30 no Marks left every... 1 500 yes yes yes Viewport... 0 7 0 4.5 select 'textgrid' Black Draw... 'display_from' 'display_until' no yes yes One mark bottom... 'point_t' yes yes yes rf1hzpt = round('f1hzpt') rf2hzpt = round('f2hzpt') Text top... no Tracker output -- F1: 'rf1hzpt' ***** F2: 'rf2hzpt' # display the spectrum, with Ltas and LPC select 'sound_16khz' spectrum_begin = 'point_t' - 0.015 spectrum_end = 'point_t' + 0.015 Extract part... 'spectrum_begin' 'spectrum_end' Hanning 1 no Rename... 'name$'_slice sound_16khz_slice = selected("Sound") To Spectrum (fft) spectrum = selected("Spectrum") Viewport... 0 7 5 9 Draw... 0 3250 0 80 yes To Ltas (1-to-1) ltas = selected("Ltas") Viewport... 0 7 5 9 Draw... 0 3250 0 80 no bars Marks bottom every... 1 500 yes yes no Marks bottom every... 1 250 no no yes select 'sound_16khz' To LPC (autocorrelation)... 18 0.025 0.005 50 lpc = selected("LPC") To Spectrum (slice)... 'point_t' 20 0 50 Rename... LPC_'name$' spectrum_lpc = selected("Spectrum") select 'lpc' Remove select 'spectrum_lpc' Line width... 2 Draw... 0 3250 0 80 no Line width... 1 Text top... no Spectrum [30 ms], Ltas(1-to-1) [30 ms], LPC(autocorrelation), all three overlaid endif if (playit = 1) select 'sound' Extract part... 'display_from' 'display_until' Hanning 1 no Play Remove endif echo 'point'of'npoints' # echo F1ref:'f1ref' * F2ref:'f2ref' * F3ref:'f3ref' * F4ref:'f4ref' * F5ref:'f5ref' * Frequency cost:'freqcost' * Bandwidth cost:'bwcost' * Transition cost:'transcost' # printline # printline This script calculates F1 and F2 at each point on a tier in a TextGrid # printline file. The label of the point - if any - is not taken into account. # printline F1 and F2 are calculated using 'To formant (burg)' and # printline and the tracker. Both of these algorithms set parameters # printline as a function of speaker sex. This parameter is controlled # printline by the user. The Picture window shows the spectrogram and # printline formant tracks (F1 & F2), and The rounded F1 and F2 values # printline appear at the top. # printline # printline As a additional check, and for voice quality measurements, # printline the script displays the spectrum, the Long-term average # printline spectrum (Ltas) and the LPC spectrum at the bottom. The # printline LPC spectrum at the bottom uses the 'autocorrelation' # printline algorithm, which is differen from the 'burg' algorithm # printline by means of which the values at the top are computed. # printline # printline When the 'To formant' and 'Track...' procedures do not # printline produce plausible formant values, the user can (1) run the # printline script again with new tracking values, (2) on the basis # printline of the spectrum/Ltas/LPC display at the bottom part of # printline the Picture window, determine F1 and F2 by hand using # printline e.g. the LPC (Spectrum LPC_slice) in the Object window. if (checkit = 1) select 'spectrum_lpc' pause ok? [point number 'counter'] endif fileappend 'spreadsheet$' 'point''tab$''int_nr''tab$''token$''tab$''point_t:3''tab$''point_l$''tab$''f0:1''tab$''f1hzpt:1''tab$''f2hzpt:1''tab$''f3hzpt:1''tab$''f1bkpt:1''tab$''f2bkpt:1''tab$''f3bkpt:1''newline$' select all minus 'sound' minus 'textgrid' minus 'sound_16khz' minus Pitch 'name$' Remove endproc Create Sound... sine 0 1 22050 1/2 * sin(2*pi*377*x) Play Play select Sound sine Remove