|
| 1 | +# Draw formant chart from segments in the sound files of a specified directory |
| 2 | +# Sound files must be .aif or .wav |
| 3 | +# TextGrid files must be .textgrid |
| 4 | +# |
| 5 | +# This script is distributed under the GNU General Public License. |
| 6 | +# Copyright Mietta Lennes 13.3.2002 |
| 7 | +# Edited by Gina Cook |
| 8 | +# v4 changed graph labels |
| 9 | +# v5 relativized version of 4 using f1 plotted against f2-f1 |
| 10 | +# v6 changed formant tracking method per male and female |
| 11 | +# v7 Nov 2010 added specific colors for specific segments |
| 12 | + |
| 13 | + |
| 14 | +form Draw a vowel chart from the centre points of selected segments, open the textgrid, wav, segments and wave files you want |
| 15 | +comment Give the name of the pair: |
| 16 | +text filename vowels-english-canada-female |
| 17 | +choice MaleFemale 2 |
| 18 | +button Male |
| 19 | +button Female |
| 20 | +comment Which tier of the TextGrid files should be used for analysis? |
| 21 | +integer Tier 1 |
| 22 | +#comment Which segments should be analysed? |
| 23 | +#sentence Segment_label a |
| 24 | +#comment Where would you like to save the results? |
| 25 | +#text resultfile results.txt |
| 26 | +comment Formant analysis options |
| 27 | +positive Time_step 0.01 |
| 28 | +integer Max_number_of_formants 5 |
| 29 | +#positive Maximum_formant_(Hz) 4500 (=adult male4500, 5500= adult female) |
| 30 | +positive Window_length_(s) 0.025 |
| 31 | +positive Preemphasis_from_(Hz) 50 |
| 32 | +choice Picture 1 |
| 33 | +button Erase the Picture window before drawing |
| 34 | +button Overlay the old picture |
| 35 | +choice Debug 1 |
| 36 | +button Print vowel label |
| 37 | +button Print vowel times |
| 38 | +endform |
| 39 | + |
| 40 | +if maleFemale = 1 |
| 41 | + maximum_formant = 4500 |
| 42 | +else if maleFemale = 2 |
| 43 | + maximum_formant = 5500 |
| 44 | +endif |
| 45 | + |
| 46 | +# Prepare the Picture window and draw a chart grid for formant analysis: |
| 47 | +if picture = 1 |
| 48 | + Erase all |
| 49 | +endif |
| 50 | +Viewport... 0 6 0 6 |
| 51 | +Font size... 12 |
| 52 | +Line width... 1 |
| 53 | +Viewport... 0 6 0 6 |
| 54 | +# To Change the Axes: Xmin Xmax Ymin Ymax |
| 55 | +# For pure F1,F2 head oriented towards the left: |
| 56 | +Axes... 3000 600 1000 100 |
| 57 | +# For relativized as F1 against F2-F1, head oriented towards the left |
| 58 | +# Axes... 2300 250 900 200 |
| 59 | +Text top... yes Vowel Space |
| 60 | +Text bottom... yes Front --------- F_2 (Hz) --------- Back |
| 61 | +Text left... yes Low --------- F_1 (Hz) --------- High |
| 62 | +Font size... 12 |
| 63 | +Marks bottom every... 1 500 yes yes yes |
| 64 | +Marks left every... 1 100 yes yes yes |
| 65 | +Plain line |
| 66 | + |
| 67 | +token = 0 |
| 68 | +# this is a "safety margin" (in seconds) for formant analysis, in case the vowel segment is very short: |
| 69 | +margin = 0.02 |
| 70 | + |
| 71 | + |
| 72 | +#Can uncomment if you want to know whether the pair were opened |
| 73 | +#printline Opened Sound and TextGrid... 'filename$' |
| 74 | + call Measurements |
| 75 | + |
| 76 | +#printline 'filename$' |
| 77 | +#printline The (F1,F2) formant points of 'token' tokens of segment "'segment_label$'" were plotted on the chart. |
| 78 | + |
| 79 | + |
| 80 | + |
| 81 | + |
| 82 | + |
| 83 | +#---------------------- |
| 84 | +procedure Measurements |
| 85 | + |
| 86 | + |
| 87 | + |
| 88 | +#make a string for colors and for segments |
| 89 | +#depends on: load the colors.strings file |
| 90 | +# select Strings colors |
| 91 | +# numberOfColors = Get number of strings |
| 92 | +# color$ = Get string... 1 |
| 93 | +select Strings segments |
| 94 | +numberOfSegments = Get number of strings |
| 95 | +#segment_label$ = Get string... 1 |
| 96 | + |
| 97 | +for segIndex to numberOfSegments |
| 98 | + select Strings segments |
| 99 | + segment_label$ = Get string... segIndex |
| 100 | + |
| 101 | + select Strings colors |
| 102 | + color$ = Get string... segIndex |
| 103 | + 'color$' |
| 104 | + #printline 'segment_label$' is 'color$' |
| 105 | + |
| 106 | + |
| 107 | +# look at the TextGrid object |
| 108 | +select TextGrid 'filename$' |
| 109 | +numberOfIntervals = Get number of intervals... tier |
| 110 | +filestart = Get starting time |
| 111 | +fileend = Get finishing time |
| 112 | + |
| 113 | +for interval to numberOfIntervals |
| 114 | + |
| 115 | +select TextGrid 'filename$' |
| 116 | +label$ = Get label of interval... tier interval |
| 117 | +if label$ = segment_label$ |
| 118 | + token = token + 1 |
| 119 | + segstart = Get starting point... tier interval |
| 120 | + segend = Get end point... tier interval |
| 121 | + |
| 122 | + # Create a window for analyses (possibly adding the "safety margin"): |
| 123 | + if (segstart - margin) > filestart |
| 124 | + windowstart = segstart - margin |
| 125 | + else |
| 126 | + windowstart = filestart |
| 127 | + endif |
| 128 | + if (segend + margin) < fileend |
| 129 | + windowend = segend + margin |
| 130 | + else |
| 131 | + windowend = fileend |
| 132 | + endif |
| 133 | + segduration = segend - segstart |
| 134 | + |
| 135 | + select Sound 'filename$' |
| 136 | + Extract part... windowstart windowend Rectangular 1 yes |
| 137 | + Rename... window |
| 138 | + |
| 139 | + # measure F1 and F2 |
| 140 | + select Sound window |
| 141 | + To Formant (burg)... time_step max_number_of_formants maximum_formant window_length preemphasis_from |
| 142 | + Rename... formants |
| 143 | + # Note: the Track command only makes sense if you have a continuous vowel segment that |
| 144 | + # you think should have a fixed number of formants. |
| 145 | + # added by gina, tried to create tracks for male vs female (lowered values by 200hz) it works, but not sure if its accurate. |
| 146 | + if maleFemale = 1 |
| 147 | + Track... 3 350 1450 2550 3650 4750 1 1 1 |
| 148 | + else if maleFemale = 2 |
| 149 | + Track... 3 550 1650 2750 3850 4950 1 1 1 |
| 150 | + endif |
| 151 | + Rename... formanttracks |
| 152 | + measurepoint = (segstart + segend) / 2 |
| 153 | + vowF1 = Get value at time... 1 measurepoint Hertz Linear |
| 154 | + vowF2 = Get value at time... 2 measurepoint Hertz Linear |
| 155 | + Viewport... 0 6 0 6 |
| 156 | + |
| 157 | + |
| 158 | + |
| 159 | + Draw circle... vowF2 vowF1 50 |
| 160 | + # if you want a vowel symbol drawn in the middle of each vowel circle, leave the next line untouched: |
| 161 | + #if to print the vowel label or the vowel times (in order to go back in the text grid and see why the formant measurements are so far off from the expected vowel quality |
| 162 | + if debug = 1 |
| 163 | + Text... vowF2 Centre vowF1 Half 'segment_label$' |
| 164 | + else if debug = 2 |
| 165 | + Text... vowF2 Centre vowF1 Half 'segstart' |
| 166 | + endif |
| 167 | + |
| 168 | + # remove the Sound object of the analysed segment |
| 169 | + select Sound window |
| 170 | + Remove |
| 171 | + # now we have to remove the original Formant object |
| 172 | + select Formant formants |
| 173 | + Remove |
| 174 | + # and also the second Formant object that was created by the Track command |
| 175 | + select Formant formanttracks |
| 176 | + Remove |
| 177 | +endif |
| 178 | + |
| 179 | +endfor |
| 180 | + |
| 181 | +#to loop through the segments |
| 182 | +endfor |
| 183 | + |
| 184 | +endproc |
| 185 | + |
| 186 | + |
0 commit comments