-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdraw_pitch.praat
More file actions
183 lines (168 loc) · 5.41 KB
/
draw_pitch.praat
File metadata and controls
183 lines (168 loc) · 5.41 KB
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# DRAW SPECTROGRAM, PITCH, AND TEXTGRID TIER
# ==========================================
# Written for Praat 6.0.40
# script by Antoin Eoin Rodgers
# rodgeran@tcd.ie
# Phonetics and speech Laboratory, Trinity College Dublin
# Jan 13, 2019
# This script draws an image showing a spectrogram, pitch contour, and single textgrid tier.
# Running the script calls a UI form before running the drawPitchPic procedure.
# The UI allows the user to choose the following:
# - image width in inches (default 6")
# - sound and pitch object index
# - textgrid index and tier to draw
# - start and end time (seconds)
# - F0 draw type (hertz or semitrones re 100 Hz)
# - minimum and maximum F0 (in hertz or semitrones)
#
# UPDATES
# 27/06/2019 Added version control to provide warning and stop script
# if running version of Praat earlier than 6.x.
###############
# USER INPUTS #
###############
form Draw spectrogram with single tier and pitch_object track
comment Picture size (width)
sentence title
natural image_width 6 (=inches)
comment Sound and pitch objects
integer sound 2 (=object number)
integer pitch_object 3 (=object number)
boolean draw_pitch
comment Textgrid information
integer text_grid 1 (=object number)
integer grid_tier 2 (=tier to display)
comment Time and F0 settings
real start_time 0 (=all)
real end_time 0 (=all)
choice f0_measurement 1
option hertz
option semitones re 100 Hz
real minimum_F0 75
real maximum_F0 500
endform
# check version compatibility
version$ = praatVersion$
if left$(version$, 1) != "6"
echo You are running Praat 'praatVersion$'.
... 'newline$'This script is designed to run on Praat version 6.0.40 or later.
... 'newline$'To run this script, update to the latest
... version at praat.org
exit
endif
### correct F0 and time errors
if minimum_F0 > maximum_F0
temp = minimum_F0
minimum_F0 = maximum_F0
maximum_F0 = temp
endif
if start_time > end_time
temp = start_time
start_time = end_time
end_time = temp
endif
#######################
# DRAW AND SAVE IMAGE #
#######################
@drawPitchPic: sound,
... text_grid,
... grid_tier,
... pitch_object,
... minimum_F0,
... maximum_F0,
... start_time,
... end_time,
... image_width,
... f0_measurement,
... title$
fileName$ = chooseWriteFile$: "Save as PNG file", drawPitchPic.saveName$
Save as 300-dpi PNG file: fileName$
##############
# PROCEDURES #
##############
procedure drawPitchPic: .sound,
... .text_grid,
... .grid_tier,
... .pitch_object,
... .minimum_F0,
... .maximum_F0,
... .start_time,
... .end_time,
... .image_width,
... .f0_measurement,
... .title$
# set tick mark size
.range = .maximum_F0 - .minimum_F0
.markDistance = round(.range/10)
# reset picture window and settings
Erase all
Black
10
Line width: 1
Select outer viewport: 0, .image_width, 0, 3.35
# extract and draw epectrogram
selectObject: .sound
.sGram = To Spectrogram: 0.005, 5000, 0.002, 20, "Gaussian"
Paint: .start_time, .end_time, 0, 5000, 100, "yes", 50, 6, 0, "no"
if draw_pitch
Marks right every: 1000, 0.500, "yes", "yes", "no"
Text right: "yes", "Spectral Frequency (kHz)"
else
Marks left every: 1000, 0.500, "yes", "yes", "no"
Text left: "yes", "Spectral Frequency (kHz)"
endif
# extract and draw textgrid tier
selectObject: .text_grid
.singleTier = Extract one tier: .grid_tier
if draw_pitch
plusObject: .pitch_object
Select outer viewport: 0, .image_width, 0, 4
if .f0_measurement = 1
Draw separately (semitones): .start_time, .end_time, .minimum_F0, .maximum_F0, "yes", "yes", "no"
endif
else
Select outer viewport: 0, .image_width, 0, 4
Draw: .start_time, .end_time, "yes", "yes", "no"
pause
endif
# draw pitch contour
if draw_pitch
White
Line width: 5
selectObject: .pitch_object
Select outer viewport: 0, .image_width, 0, 3.35
if .f0_measurement = 1
Draw: .start_time, .end_time, .minimum_F0, .maximum_F0, "no"
Blue
Line width: 3
Draw: .start_time, .end_time, .minimum_F0, .maximum_F0, "no"
Line width: 1
Black
Marks left every: 1, .markDistance, "yes", "yes", "no"
Text left: "yes", "Fundamental Frequency (Hz)"
else
Draw semitones (re 100 Hz): .start_time, .end_time, .minimum_F0, .maximum_F0, "no"
Blue
Line width: 3
Draw semitones (re 100 Hz): .start_time, .end_time, .minimum_F0, .maximum_F0, "no"
Line width: 1
Black
Marks left every: 1, .markDistance, "yes", "yes", "no"
Text left: "yes", "Fundamental Frequency (semitones re 100 Hz)"
endif
endif
# draw remaining image elements
Draw inner box
Select outer viewport: 0, .image_width, 0, 4
Marks bottom every: 0.001, 200, "yes", "yes", "no"
Marks bottom every: 0.001, 100, "no", "yes", "no"
Text bottom: "yes", "Time (ms)"
.saveName$ = .title$ + ".png"
12
Text top: "yes", .title$
10
# remove objects
selectObject: .sGram
plusObject: .singleTier
Remove
endproc