###Description of this script ## This script measures the first three formants at the startpoint and endpoint of vowels, and appends the ## results to a csv file. It will be called "formantout.xls", 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$ = "D:\3工作\2018年下半年\实验语音学\声调与元音开口度录音事宜\罗天禹\ai\" ## Now we will do some prep work to get your output file ready. The first thing I usually do is ## make sure that I delete any pre-existing variant of the output file: filedelete 'directory$'formantoutput.xls ## Now I'm going to make a variable called "header_row$", then write that variable to the output file: header_row$ = "speaker" + tab$ + "vowel" + tab$ + "context" + tab$ + "F1" + tab$ + "F2" + tab$ + "F3" + tab$ + "gl F1" + tab$ + "gl F2"+ tab$ + "gl F3" + newline$ header_row$ > 'directory$'formantoutput.xls ## 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: select Sound 'object_name$' # 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' select Formant 'object_name$' f_one_1 = Get value at time... 1 'begin_vowel' Hertz Linear f_two_1 = Get value at time... 2 'begin_vowel' Hertz Linear f_three_1 = Get value at time... 3 'begin_vowel' Hertz Linear f_one_2 = Get value at time... 1 'end_vowel' Hertz Linear f_two_2 = Get value at time... 2 'end_vowel' Hertz Linear f_three_2 = Get value at time... 3 'end_vowel' Hertz Linear fileappend "'directory$'formantoutput.xls" 'object_name$''tab$'"ai"'tab$''interval_label$''tab$''f_one_1:0''tab$''f_two_1:0''tab$''f_three_1:0''tab$''f_one_2:0''tab$''f_two_2:0''tab$''f_three_2:0''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 output 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. revised by Qibin Ran. ## crosswhi@ling.rochester.edu; ranqibin@126.com