-
Notifications
You must be signed in to change notification settings - Fork 24
/
play_vowels_draw_formant_chart.praat
133 lines (109 loc) · 2.96 KB
/
play_vowels_draw_formant_chart.praat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# Draw formant chart from selected segments according to a TextGrid object
#
# This script is distributed under the GNU General Public License.
# Copyright Mietta Lennes 8.3.2002
form Draw a vowel chart from the centre points of selected segments in a Sound object
integer Tier 1
sentence Segment_label a
comment You can also give a small "safety margin" around each vowel segment for formant calculation.
positive Margin 0.05
endform
gridname$ = selected$ ("TextGrid", 1)
soundname$ = selected$ ("Sound", 1)
Create Sound... silence 0 0.5 22050 0
Viewport... 0 6 6.5 9
Font size... 18
Line width... 1
Viewport... 0 6 0 6
Axes... 100 900 600 2900
Text top... yes Formant chart of ''segment_label$'' segments
Text bottom... yes F_1 (Hz)
Text left... yes F_2 (Hz)
Font size... 14
Marks bottom every... 1 100 yes yes yes
Marks left every... 1 500 yes yes yes
endif
Plain line
#---------
select TextGrid 'gridname$'
numberOfIntervals = Get number of intervals... tier
start = Get starting time
end = Get finishing time
token = 0
for interval to numberOfIntervals
echo Analyzing segment number 'interval' / 'numberOfIntervals'
select TextGrid 'gridname$'
label$ = Get label of interval... tier interval
if label$ = segment_label$
token = token + 1
select TextGrid 'gridname$'
segStart = Get starting point... tier interval
segEnd = Get end point... tier interval
# Create a window for analyses
if (segStart - margin) > start
winStart = segStart - margin
else
winStart = start
endif
if (segEnd + margin) < end
winEnd = segEnd + margin
else
winEnd = end
endif
vowDur = segEnd - segStart
select Sound 'soundname$'
Extract part... winStart winEnd Rectangular 1 yes
Rename... window
# measure F1 and F2
select Sound window
To Formant (burg)... 0.01 5 5500 0.025 50
Rename... formants
Track... 3 550 1650 2750 3850 4950 1 1 1
measurepoint = (segStart + segEnd) / 2
vowF1 = Get value at time... 1 measurepoint Hertz Linear
vowF2 = Get value at time... 2 measurepoint Hertz Linear
Viewport... 0 6 0 6
Draw circle... vowF1 vowF2 27
# play the sound and the environment a couple of times...
select Sound 'soundname$'
Extract part... segStart segEnd Rectangular 1 yes
Rename... seg_window
Play
select Sound silence
Play
if winStart - 0.2 < start
bigstart = start
else
bigstart = winStart - 0.2
endif
if winStart + 0.2 > end
bigend = end
else
bigend = winEnd + 0.2
endif
select Sound 'soundname$'
Extract part... bigstart bigend Rectangular 1 yes
Rename... big_window
Play
Remove
select Sound silence
Play
select Sound seg_window
Play
select Sound silence
Play
select Sound seg_window
Play
Remove
# finished playing
pause Do you want to see and hear the next segment 'segment_label$'?
select Sound window
Remove
select Formant formants
Remove
select Formant formants
Remove
endif
endfor
printline The (F1,F2) formant points of 'token' vowel tokens were plotted on the chart.
printline Finished drawing!