###Description of this script ## This script measures f0 and the first three formants at the midpoint of the vowel, and appends the ## results to a text file. It will be called "formant-log.txt", and will be written to the same ## directory holding your sound files. ## To run this script, you will have to have a bunch of sound files with accompanying text grids. The ## locations of vowels to be measured must be marked in tier 1 of the textgrid. Anything with a non-null ## label in that tier will be logged. ###End of description ## Specify the directory containing your sound files in the next line: directory$ = "C:\Users\Administrator\Desktop\田弘瑶佳相关材料\双峰标注尝试\" ## Now we will do some prep work to get your log file ready. The first thing I usually do is ## make sure that I delete any pre-existing variant of the log: filedelete 'directory$'formant-log.txt ## Now I'm going to make a variable called "header_row$", then write that variable to the log file: header_row$ = "Filename" + tab$ + "phoneme" + tab$ + "F0" + tab$ + "F1" + tab$ + "F2" + tab$ + "F3" + tab$ + "Duration (ms.)" + newline$ header_row$ > 'directory$'formant-log.txt ## The next three lines are a form that will pop up when the script is run, allowing the ## user to specify speaker gender. form Enter speaker gender (m or f only) sentence Gender f endform ## Now we make a list of all the sound files in the directory we're using, and put the number of ## filenames into the variable "number_of_files": Create Strings as file list... list 'directory$'*.wav number_files = Get number of strings # Then we set up a "for" loop that will iterate once for every file in the list: for j from 1 to number_files # Query the file-list to get the first filename from it, then read that file in: select Strings list current_token$ = Get string... 'j' Read from file... 'directory$''current_token$' # Here we make a variable called "object_name$" that will be equal to the filename minus the ".wav" extension: object_name$ = selected$ ("Sound") # Now we do a formant analysis on the current sound file. Note that we first have to re-select the sound # object. We then use an if statement to make sure that we use a maximum frequency of # 5500 for female speakers and 5000 for male speakers. We aren't going to do anything with the # formant analysis right away -- we will be coming back to it later to get the values we want. if gender$ = "f" To Formant (burg)... 0.0025 5 5500 0.025 50 else To Formant (burg)... 0.0025 5 5000 0.025 50 endif # Now we'll re-select the sound object, and do a pitch analysis: select Sound 'object_name$' To Pitch... 0.01 75 600 # Now we get the corresponding TextGrid and read it in: Read from file... 'directory$''object_name$'.TextGrid # Now we query the TextGrid to get find out how many intervals there are in tier 1, storing # that number in a variable called "number_of_intervals". This is used to set up a for loop # that will be used to go through each of the intervals and measure it (if its label is non-null). select TextGrid 'object_name$' number_of_intervals = Get number of intervals... 1 for b from 1 to number_of_intervals select TextGrid 'object_name$' interval_label$ = Get label of interval... 1 'b' if interval_label$ <> "" begin_vowel = Get starting point... 1 'b' end_vowel = Get end point... 1 'b' midpoint = begin_vowel + ((end_vowel - begin_vowel) / 2) select Formant 'object_name$' f_one = Get value at time... 1 'midpoint' Hertz Linear f_two = Get value at time... 2 'midpoint' Hertz Linear f_three = Get value at time... 3 'midpoint' Hertz Linear select Pitch 'object_name$' f_zero = Get value at time... 'midpoint' Hertz Linear duration = (end_vowel - begin_vowel) * 1000 fileappend "'directory$'formant-log.txt" 'object_name$''tab$''interval_label$''tab$''f_zero:0''tab$''f_one:0''tab$''f_two:0''tab$''f_three:0''tab$''duration:3''newline$' endif endfor # By this point, we have gone through all the intervals for the current sound object and # textgrid, and written all the appropriate values to our log file. We are now ready to go on to # the next file, so we close can get rid of any objects we no longer need, and end our for loop select all minus Strings list Remove endfor # And at the end, a little bit of clean up and a message to let you know that it's all done. select all Remove clearinfo print All files have been processed. What next? ## written by Katherine Crosswhite ## crosswhi@ling.rochester.edu