-
Notifications
You must be signed in to change notification settings - Fork 0
/
draw.praat
137 lines (123 loc) · 3.85 KB
/
draw.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
133
134
135
136
137
# Author: Chunyu Ge 葛淳宇
# Updated: 2019-12-06
# Usage: - Draw pictures of a sound file according to the TextGrid
# - Optional: draw TextGrid together with the waveform or the spectrogram
# - Optional: draw pitch together with the waveform or the spectrogram
# Cautions: - Use forward slash "/" instead of backward slash "\" in the path
# - Do not add extension to the file name
form Draw a picture
comment Where is the sound file? (Use "/" instead of "\")
sentence filePath D:/changzhou/2_annotation/F1/bisyllabic/
comment The file name of the sound file (Do not include extension)
word baseName F1_B0212
comment Where would you like to save the pictures?
sentence savePath C:/Users/Hu/Desktop/
#comment The start time of the picture (in second)
#real start 1.25
#comment The end time of the picture (in second)
#real end 2.44
comment Do you want to draw the TextGrid together with the sound?
boolean drawTg yes
comment Do you want to draw the pitch together with the sound?
boolean drawPitch yes
endform
if right$(filePath$) <> "/"
filePath$ = filePath$ + "/"
endif
if right$(savePath$) <> "/"
savePath$ = savePath$ + "/"
endif
Read from file: filePath$ + baseName$ + ".wav"
Read from file: filePath$ + baseName$ + ".TextGrid"
floor = 75
ceiling = 300
selectObject: "TextGrid " + baseName$
n = Get number of intervals: 1
start = Get start time of interval: 1, 2
picStart = start - 0.05
end = Get end time of interval: 1, n-1
picEnd = end + 0.05
Erase all
@draw_waveform: baseName$, picStart, picEnd
if drawTg
@draw_TextGrid: baseName$, picStart, picEnd
endif
if drawPitch
@draw_pitch: baseName$, floor, ceiling, picStart, picEnd
endif
if drawTg
Select inner viewport: 1, 4, 1, 3
else
Select inner viewport: 1, 4, 1, 2.15
Draw inner box
Axes: 0, picEnd - picStart, 0, 5000
Marks bottom: 5, "yes", "yes", "no"
Text bottom: "yes", "Time (s)"
endif
Save as 600-dpi PNG file: savePath$ + baseName$ + "-waveform.png"
Erase all
@draw_spectrogram: baseName$, picStart, picEnd
if drawTg
@draw_TextGrid: baseName$, picStart, picEnd
endif
if drawPitch
@draw_pitch: baseName$, floor, ceiling, picStart, picEnd
endif
if drawTg
Select inner viewport: 1, 4, 1, 3
else
Select inner viewport: 1, 4, 1, 2.15
Draw inner box
Axes: 0, picEnd - picStart, 0, 5000
Marks bottom: 5, "yes", "yes", "no"
Text bottom: "yes", "Time (s)"
endif
Save as 600-dpi PNG file: savePath$ + baseName$ + "-spectrogram.png"
Erase all
select all
Remove
procedure draw_TextGrid: .baseName$, .start, .end
selectObject: "TextGrid " + .baseName$
Select inner viewport: 1, 4, 1, 3
Draw: .start, .end, "yes", "yes", "no"
Draw inner box
Axes: 0, .end - .start, 0, 5000
Marks bottom: 5, "yes", "yes", "no"
Text bottom: "yes", "Time (s)"
endproc
procedure draw_waveform: .baseName$, .start, .end
selectObject: "Sound " + baseName$
Select inner viewport: 1, 4, 1, 2.15
Draw: .start, .end, 0, 0, "no", "Curve"
endproc
procedure draw_spectrogram: .baseName$, .start, .end
selectObject: "Sound " + .baseName$
To Spectrogram: 0.005, 5000, 0.002, 20, "Gaussian"
selectObject: "Spectrogram " + .baseName$
Select inner viewport: 1, 4, 1, 2.15
Paint: .start, .end, 0, 5000, 100, "yes", 50, 6, 0, "no"
Axes: .start, .end, 0, 5000
Marks left: 6, "yes", "yes", "no"
Text left: "yes", "Frequency (Hz)"
endproc
procedure smooth_pitch: .baseName$, .floor, .ceiling
selectObject: "Sound " + .baseName$
To Pitch: 0, .floor, .ceiling
selectObject: "Pitch " + baseName$
Smooth: 10
Rename: "smooth"
endproc
procedure draw_pitch: .baseName$, .floor, .ceiling, .start, .end
@smooth_pitch: .baseName$, .floor, .ceiling
selectObject: "Pitch smooth"
Select inner viewport: 1, 4, 1, 2.15
Axes: 0, .end - .start, 0, .ceiling
Line width: 3
#Font size: 14
Colour: "Blue"
Draw: .start, .end, 0, .ceiling, "no"
Line width: 1
Colour: "Black"
Marks right: 4, "yes", "yes", "no"
Text right: "yes", "Pitch (Hz)"
endproc